Adding connection strings to a production app
I have an app ready for production. For it to work, each client needs to set a unique url to access their data. How would i prepare the app for making it easy to add a url as an access point to the clients?
Would a correct way to do this be to add it in the manifest.json file and somehow reference it from there? (Until now in development i've only used a global URL in a js file)
reactjs production
add a comment |
I have an app ready for production. For it to work, each client needs to set a unique url to access their data. How would i prepare the app for making it easy to add a url as an access point to the clients?
Would a correct way to do this be to add it in the manifest.json file and somehow reference it from there? (Until now in development i've only used a global URL in a js file)
reactjs production
A.env
environment file or aaoo-config.js
will help you here.
– kiranvj
Nov 14 '18 at 9:24
add a comment |
I have an app ready for production. For it to work, each client needs to set a unique url to access their data. How would i prepare the app for making it easy to add a url as an access point to the clients?
Would a correct way to do this be to add it in the manifest.json file and somehow reference it from there? (Until now in development i've only used a global URL in a js file)
reactjs production
I have an app ready for production. For it to work, each client needs to set a unique url to access their data. How would i prepare the app for making it easy to add a url as an access point to the clients?
Would a correct way to do this be to add it in the manifest.json file and somehow reference it from there? (Until now in development i've only used a global URL in a js file)
reactjs production
reactjs production
asked Nov 14 '18 at 9:15
melbilmelbil
356
356
A.env
environment file or aaoo-config.js
will help you here.
– kiranvj
Nov 14 '18 at 9:24
add a comment |
A.env
environment file or aaoo-config.js
will help you here.
– kiranvj
Nov 14 '18 at 9:24
A
.env
environment file or a aoo-config.js
will help you here.– kiranvj
Nov 14 '18 at 9:24
A
.env
environment file or a aoo-config.js
will help you here.– kiranvj
Nov 14 '18 at 9:24
add a comment |
2 Answers
2
active
oldest
votes
You need to install the package dotenv package and create a .env
file in your root directory which should contain your environment variables.
Assuming that the URl you are referring to is http://localhost:3000/some/url
on your localhost, then your .env
file might look like:
MY_URL=http://localhost:3000/some/url
Then in your react application, you can get the value of MY_URL
by doing:
const url = process.env.MY_URL
Note that if you are using the create-react-app package, then you do not need to install the dotenv package since it already comes with the create-react-app package. Also you need to change it:
REACT_APP_MY_URL=http://localhost:3000/some/url
Also make sure to add the .env
file to your .gitignore
file so that you do not push it to your repo.
Assuming that you are deploying your application to Heroku. Heroku provides a simple interface which allows you to add your environment variables which looks like:
That's it.
This would work if i only had to declare the variable at build time, but i need this to work at runtime
– melbil
Nov 14 '18 at 12:08
Not true, this will work both at build time or runtime. Can you explain what you mean?
– lomse
Nov 14 '18 at 12:16
I have a unejected create-react-app with a .env pointing to a location. I then do a 'npm run build' and get a bunch of files produced in the build folder. Then i run 'serve -s build'. And here is my problem - as i do not know the actual url the app will be using, i have to inject it into the app at a later stage. Currently it points to the url used in development, but this needs to be changed. How would i do that? I tried creating a new .env file in build folder, but no luck
– melbil
Nov 14 '18 at 12:20
Which platform are you deploying your app to?
– lomse
Nov 14 '18 at 13:42
1
So you can start by renaming the .env file to env.sample which will contain dummy data is can be pushed to your repo. In yourhere-is-how-you-connect-the-app-to-your-database
file, let the user know that they need to replace the dummy values with the appropriate values and add them to Azure. You can check how to set environment variables on Azure docs.microsoft.com/en-us/azure/container-instances/…
– lomse
Nov 14 '18 at 15:19
|
show 3 more comments
Maybe you could store them in environment variables?
that way you can always edit them later without having to change components.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53296611%2fadding-connection-strings-to-a-production-app%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to install the package dotenv package and create a .env
file in your root directory which should contain your environment variables.
Assuming that the URl you are referring to is http://localhost:3000/some/url
on your localhost, then your .env
file might look like:
MY_URL=http://localhost:3000/some/url
Then in your react application, you can get the value of MY_URL
by doing:
const url = process.env.MY_URL
Note that if you are using the create-react-app package, then you do not need to install the dotenv package since it already comes with the create-react-app package. Also you need to change it:
REACT_APP_MY_URL=http://localhost:3000/some/url
Also make sure to add the .env
file to your .gitignore
file so that you do not push it to your repo.
Assuming that you are deploying your application to Heroku. Heroku provides a simple interface which allows you to add your environment variables which looks like:
That's it.
This would work if i only had to declare the variable at build time, but i need this to work at runtime
– melbil
Nov 14 '18 at 12:08
Not true, this will work both at build time or runtime. Can you explain what you mean?
– lomse
Nov 14 '18 at 12:16
I have a unejected create-react-app with a .env pointing to a location. I then do a 'npm run build' and get a bunch of files produced in the build folder. Then i run 'serve -s build'. And here is my problem - as i do not know the actual url the app will be using, i have to inject it into the app at a later stage. Currently it points to the url used in development, but this needs to be changed. How would i do that? I tried creating a new .env file in build folder, but no luck
– melbil
Nov 14 '18 at 12:20
Which platform are you deploying your app to?
– lomse
Nov 14 '18 at 13:42
1
So you can start by renaming the .env file to env.sample which will contain dummy data is can be pushed to your repo. In yourhere-is-how-you-connect-the-app-to-your-database
file, let the user know that they need to replace the dummy values with the appropriate values and add them to Azure. You can check how to set environment variables on Azure docs.microsoft.com/en-us/azure/container-instances/…
– lomse
Nov 14 '18 at 15:19
|
show 3 more comments
You need to install the package dotenv package and create a .env
file in your root directory which should contain your environment variables.
Assuming that the URl you are referring to is http://localhost:3000/some/url
on your localhost, then your .env
file might look like:
MY_URL=http://localhost:3000/some/url
Then in your react application, you can get the value of MY_URL
by doing:
const url = process.env.MY_URL
Note that if you are using the create-react-app package, then you do not need to install the dotenv package since it already comes with the create-react-app package. Also you need to change it:
REACT_APP_MY_URL=http://localhost:3000/some/url
Also make sure to add the .env
file to your .gitignore
file so that you do not push it to your repo.
Assuming that you are deploying your application to Heroku. Heroku provides a simple interface which allows you to add your environment variables which looks like:
That's it.
This would work if i only had to declare the variable at build time, but i need this to work at runtime
– melbil
Nov 14 '18 at 12:08
Not true, this will work both at build time or runtime. Can you explain what you mean?
– lomse
Nov 14 '18 at 12:16
I have a unejected create-react-app with a .env pointing to a location. I then do a 'npm run build' and get a bunch of files produced in the build folder. Then i run 'serve -s build'. And here is my problem - as i do not know the actual url the app will be using, i have to inject it into the app at a later stage. Currently it points to the url used in development, but this needs to be changed. How would i do that? I tried creating a new .env file in build folder, but no luck
– melbil
Nov 14 '18 at 12:20
Which platform are you deploying your app to?
– lomse
Nov 14 '18 at 13:42
1
So you can start by renaming the .env file to env.sample which will contain dummy data is can be pushed to your repo. In yourhere-is-how-you-connect-the-app-to-your-database
file, let the user know that they need to replace the dummy values with the appropriate values and add them to Azure. You can check how to set environment variables on Azure docs.microsoft.com/en-us/azure/container-instances/…
– lomse
Nov 14 '18 at 15:19
|
show 3 more comments
You need to install the package dotenv package and create a .env
file in your root directory which should contain your environment variables.
Assuming that the URl you are referring to is http://localhost:3000/some/url
on your localhost, then your .env
file might look like:
MY_URL=http://localhost:3000/some/url
Then in your react application, you can get the value of MY_URL
by doing:
const url = process.env.MY_URL
Note that if you are using the create-react-app package, then you do not need to install the dotenv package since it already comes with the create-react-app package. Also you need to change it:
REACT_APP_MY_URL=http://localhost:3000/some/url
Also make sure to add the .env
file to your .gitignore
file so that you do not push it to your repo.
Assuming that you are deploying your application to Heroku. Heroku provides a simple interface which allows you to add your environment variables which looks like:
That's it.
You need to install the package dotenv package and create a .env
file in your root directory which should contain your environment variables.
Assuming that the URl you are referring to is http://localhost:3000/some/url
on your localhost, then your .env
file might look like:
MY_URL=http://localhost:3000/some/url
Then in your react application, you can get the value of MY_URL
by doing:
const url = process.env.MY_URL
Note that if you are using the create-react-app package, then you do not need to install the dotenv package since it already comes with the create-react-app package. Also you need to change it:
REACT_APP_MY_URL=http://localhost:3000/some/url
Also make sure to add the .env
file to your .gitignore
file so that you do not push it to your repo.
Assuming that you are deploying your application to Heroku. Heroku provides a simple interface which allows you to add your environment variables which looks like:
That's it.
answered Nov 14 '18 at 9:53
lomselomse
1,30442646
1,30442646
This would work if i only had to declare the variable at build time, but i need this to work at runtime
– melbil
Nov 14 '18 at 12:08
Not true, this will work both at build time or runtime. Can you explain what you mean?
– lomse
Nov 14 '18 at 12:16
I have a unejected create-react-app with a .env pointing to a location. I then do a 'npm run build' and get a bunch of files produced in the build folder. Then i run 'serve -s build'. And here is my problem - as i do not know the actual url the app will be using, i have to inject it into the app at a later stage. Currently it points to the url used in development, but this needs to be changed. How would i do that? I tried creating a new .env file in build folder, but no luck
– melbil
Nov 14 '18 at 12:20
Which platform are you deploying your app to?
– lomse
Nov 14 '18 at 13:42
1
So you can start by renaming the .env file to env.sample which will contain dummy data is can be pushed to your repo. In yourhere-is-how-you-connect-the-app-to-your-database
file, let the user know that they need to replace the dummy values with the appropriate values and add them to Azure. You can check how to set environment variables on Azure docs.microsoft.com/en-us/azure/container-instances/…
– lomse
Nov 14 '18 at 15:19
|
show 3 more comments
This would work if i only had to declare the variable at build time, but i need this to work at runtime
– melbil
Nov 14 '18 at 12:08
Not true, this will work both at build time or runtime. Can you explain what you mean?
– lomse
Nov 14 '18 at 12:16
I have a unejected create-react-app with a .env pointing to a location. I then do a 'npm run build' and get a bunch of files produced in the build folder. Then i run 'serve -s build'. And here is my problem - as i do not know the actual url the app will be using, i have to inject it into the app at a later stage. Currently it points to the url used in development, but this needs to be changed. How would i do that? I tried creating a new .env file in build folder, but no luck
– melbil
Nov 14 '18 at 12:20
Which platform are you deploying your app to?
– lomse
Nov 14 '18 at 13:42
1
So you can start by renaming the .env file to env.sample which will contain dummy data is can be pushed to your repo. In yourhere-is-how-you-connect-the-app-to-your-database
file, let the user know that they need to replace the dummy values with the appropriate values and add them to Azure. You can check how to set environment variables on Azure docs.microsoft.com/en-us/azure/container-instances/…
– lomse
Nov 14 '18 at 15:19
This would work if i only had to declare the variable at build time, but i need this to work at runtime
– melbil
Nov 14 '18 at 12:08
This would work if i only had to declare the variable at build time, but i need this to work at runtime
– melbil
Nov 14 '18 at 12:08
Not true, this will work both at build time or runtime. Can you explain what you mean?
– lomse
Nov 14 '18 at 12:16
Not true, this will work both at build time or runtime. Can you explain what you mean?
– lomse
Nov 14 '18 at 12:16
I have a unejected create-react-app with a .env pointing to a location. I then do a 'npm run build' and get a bunch of files produced in the build folder. Then i run 'serve -s build'. And here is my problem - as i do not know the actual url the app will be using, i have to inject it into the app at a later stage. Currently it points to the url used in development, but this needs to be changed. How would i do that? I tried creating a new .env file in build folder, but no luck
– melbil
Nov 14 '18 at 12:20
I have a unejected create-react-app with a .env pointing to a location. I then do a 'npm run build' and get a bunch of files produced in the build folder. Then i run 'serve -s build'. And here is my problem - as i do not know the actual url the app will be using, i have to inject it into the app at a later stage. Currently it points to the url used in development, but this needs to be changed. How would i do that? I tried creating a new .env file in build folder, but no luck
– melbil
Nov 14 '18 at 12:20
Which platform are you deploying your app to?
– lomse
Nov 14 '18 at 13:42
Which platform are you deploying your app to?
– lomse
Nov 14 '18 at 13:42
1
1
So you can start by renaming the .env file to env.sample which will contain dummy data is can be pushed to your repo. In your
here-is-how-you-connect-the-app-to-your-database
file, let the user know that they need to replace the dummy values with the appropriate values and add them to Azure. You can check how to set environment variables on Azure docs.microsoft.com/en-us/azure/container-instances/…– lomse
Nov 14 '18 at 15:19
So you can start by renaming the .env file to env.sample which will contain dummy data is can be pushed to your repo. In your
here-is-how-you-connect-the-app-to-your-database
file, let the user know that they need to replace the dummy values with the appropriate values and add them to Azure. You can check how to set environment variables on Azure docs.microsoft.com/en-us/azure/container-instances/…– lomse
Nov 14 '18 at 15:19
|
show 3 more comments
Maybe you could store them in environment variables?
that way you can always edit them later without having to change components.
add a comment |
Maybe you could store them in environment variables?
that way you can always edit them later without having to change components.
add a comment |
Maybe you could store them in environment variables?
that way you can always edit them later without having to change components.
Maybe you could store them in environment variables?
that way you can always edit them later without having to change components.
answered Nov 14 '18 at 9:20
Teun van der WijstTeun van der Wijst
570315
570315
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53296611%2fadding-connection-strings-to-a-production-app%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
A
.env
environment file or aaoo-config.js
will help you here.– kiranvj
Nov 14 '18 at 9:24