Getting process.env to work with HERE API keys - here-api

I'm building a React geographic todo list, similar to this one. I was using a Mapbox API for the mapping component, but I'd like to switch it over to HERE's Map Image API. I've set up the map on my app, but I'd like to hide my app_id and app_code in the .env file I had previously created. Is this possible? I know it's also possible to restrict which domains have access to the key/code, but I wanted to keep the keys hidden in a .env file for peace of mind.
Here is my .env file (without the keys, of course):
REACT_APP_HERE_ID={my app_id}
REACT_APP_HERE_CODE={my app_code}
And here is where I'm introducing it into my App:
const app_id = process.env.REACT_APP_HERE_ID;
const app_code = process.env.REACT_APP_HERE_CODE;
When I console.log app_id and app_code, they both return undefined. The previous API key I had from Mapbox worked fine in my .env file, but I can't seem to get the app_id and app_code from HERE to be recognized the same way.
Am I missing something? Is it easier to just limit which domains are able to use my id & code?

I assume you are using 'react-scripts' module for building/starting your project. Also as per above description, I can see you are using correct prefix 'REACT_APP_' to declare any variable in your .env file.
Just do a fresh build of app using command:
npm run-scripts build
or Just restart your app using :
npm react-scripts start
I think it should work fine.
And, Yes you can limit which domain should use your AppID and AppCode, using the feature "Secure app credentials against a specific domain" provided at https://developer.here.com/, just below the place where you see your id and code.
Hope this helps.

Related

Firebase dynamic links on customdomain rewrite in hosting but how

I've setup a custom domain to use for firebase Dynamic Links. Hosting has been setup in Firebase Console and I tried to use dynamic links without the customdomain, but just a xxx.page.link.
Now I want to return to use the custom domain, but from the console I'm told that:
A configuration already exists for this site. Add the snippet below to your firebase.json file and redeploy your changes. Be sure the rewrite rule is the first match for your dynamic link.
I'm not exactly sure how to handle this. Should I use the CLI and init a project to make this change or can I somehow do this from the portal itself.
If I need to use the CLI, how do I then access the existing project and make the change?
It seems you're already using Firebase Hosting outside of just for Dynamic Links. In that case you'll need to configure it through the CLI.
The configuration for Firebase Hosting must be made through deploying the firebase.json file through the Firebase CLI. There's no way to configure this directly in the Firebase console.
You can create an empty directory, run firebase init in there, and configure it to your existing project. Once that is done, you can create and deploy the minimal firebase.json file required as shown in the documentation on setting up your custom domain.

my NativeScript app dosent display the google maps

here is my code :
https://github.com/jonny720/do-here-client/tree/master/do-here
i took the map component code from here :
https://github.com/dapriett/nativescript-google-maps-sdk/tree/master/ng-demo/app/map
the map component should display the google maps but nothing is shown.
*i installed google maps sdk, and setup the api key in the android platform.
its the first time i'm working with api in my app.
can someone light my eyes and tell me what is the problem?
The api key is missing and you should register custom element in main.ts file, and the 2 files to copy from the nativescript-google-map module were missing from your app folder
and as well as the key too.
I forked your repo and update the app, also created a .gitignore file to exclude unnecessary files and folder from repo.
I tested and it works fine.
You will have to update these files with your appropriate Google API key
> do-here/app/main.ts
> do-here/app/App_Resources/Android/values/nativescript_google_maps_api.xml
> do-here/app/App_Resources/Android/src/main/res/values/nativescript_google_maps_api.xml
and update this file to redirect all unauthorized access back to login page, changed it to test the map page
do-here/app/#shared/services/auth-guard.service.ts
ok first thank you a lot KielSoft
i solved it by typing in the cli :
tns tun android --clean

Firebase Deployed URL not working?

So I have built a simple firebase and javascript app that uses firebase database and hosting.
I have successfully built the app and deployed to Firebase hosting, however when the cmd provides the url that leads to the app it takes me to some completely random firebase landing page.
All deployment is correct and I know all my code is correct, but it keeps sending me to the random landing page: https://firebase.google.com/docs/hosting/
When you first create a project on firebase it asks you for the public directory: What do you want to use as your public directory? public
Usually the default its public, so the firebase generates a random welcome index.html there.
When you setup the firebase init configure the public directory to your files and you should see your app instead of the welcome index file, or simply put all your files inside the public directory you've chosen above.
Here I found a very simple tutorial on how to get started on that: https://www.brooks-patton.com/deploying-a-static-website-to-firebase/
Another way - you can just edit firebase.json file, in the line with "public" change the path where is your code was built.

'firebase serve...'. Web service URL returns "Function X in location us-central1 in project Y does not exist"

I have been happily running a Firebase web 'function' for a while via firebase serve --only functions.
But something has gone awry (after I simply tried to move the project folder on my disk - You've probably seen my other post... Anyway, I have put stuff back at the original location and now I have a new problem).
When I run the function locally now, and hit the local web URL, I get this:
(And there is no evidence my request callback code is ever called)
{"error":{"code":404,"status":"NOT_FOUND",
"message":"Function FredSays in location us-central1 in project fred-says does not exist",
"errors":["Function FredSays in location us-central1 in project fred-says does not exist"]}}
This seems to be Firebase doing some sort of sanity checking on the request before ever calling my code.
If I look in either the Firebase console, or the google cloud console, the function DOES exist with the right names and locations.
Any idea what is going wrong and how to fix this?
I had the same error.
I found my fix by checking the following things:
Make sure that in the functions folder the package.json "main" property point's to the right path & that the file exists (index.js).
If you're using TypeScript make sure that the .ts file gets converted to a valid .js file. Also check the tsconfig.json "target" property to compile to ES5.

How to separate Meteor project into modules

My Meteor project has two part:
Home page: can be visited by anyone.
Admin Console: provide some management tools to administrator only
When I running this project in production mode:
$ meteor --production
Meteor will combine all the client side code into one big file, that make "Admin Console" code also delivered to normal visitors.
Is there any way to "minify" javascript/css files into two files?
one for normal visitor, one for admin?
I also pack this project into Android package, "Admin Console" code also exists in apk file, how can I exclude them ?
Thanks.
You can use meteor dynamic imports to only download code to the client based on the view the client is using. I have not tried this yet, but it should be possible to not load files dynamically based on the user's role.
Something like:
//must be called inside a meteor method or publish function
async function adminOnlyApi() {
if(Roles.userIsInRole(Meteor.userId, ['admin']) {
return await import('path/to/lib');
}
return {};
}
Assuming the lib exports a default object with a key 'foo' and value 'bar', calling adminOnlyApi.foo when logged in as admin should return 'bar', and return undefined when logged in with any other user...

Resources