separate-env-module | Tear your variables | Frontend Framework library
kandi X-RAY | separate-env-module Summary
kandi X-RAY | separate-env-module Summary
Separated environment variables for server and client build. :warning: With Nuxt v2.13 you might want to use the new runtime config instead of this.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of separate-env-module
separate-env-module Key Features
separate-env-module Examples and Code Snippets
Community Discussions
Trending Discussions on separate-env-module
QUESTION
I've researched and found three different possibilities to solving my case: I'd like to make an async API call (using dotenv variables to store the credentials) and commit the returned data to Vuex on app init --keeping the creds secure.
Currently I'm attempting using serverMiddleware, but I'm having trouble accessing the context. Is this possible? Currently just getting a "store is not defined" error.
Also, after researching, I keep seeing that it's not a good idea to use regular middleware, as running any code on the client-side exposes the env variable... But I'm confused. Doesn't
if (!process.client) { ... }
take care of this? Or am I missing the bigger picture.Additionally, if it does turn out to be okay to use middleware to secure the credentials, would using the separate-env-module be wise to make doubly sure that nothing gets leaked client-side?
Thanks, I'm looking forward to understanding this more thoroughly.
...ANSWER
Answered 2019-Oct-18 at 15:54You can use serverMiddleware
.
You can do it like this:
client -> call serverMiddleware -> servermiddleware calls API.
that way API key is not in client but remains on the server.
Example:
remote api is: https://maps.google.com/api/something
your api: https://awesome.herokuapp.com
since your own api has access to environment variables and you don't want the api key to be included in the generated client-side build, you create a serverMiddleware
that will proxy the request for you.
So that in the end, your client will just make a call to https://awesome.herokuapp.com/api/maps
, but that endpoint will just call https://maps.google.com/api/something?apikey=123456
and return the response back to you
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install separate-env-module
Add @nuxtjs/separate-env to the modules section of nuxt.config.js
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page