In this lesson, we'll make a few small changes to our scripts and add some environment variables that'll be used at Buil D time to get application the deployed to a production environment using the now service. Once properly configured, we ll use the now CLI and publish our application to a production server.
React. env file by default, add a. env file in the root folder:
React_app_base_url=http://Localhost:9001/todos
Which just holding our API configuration.
Also create a. env.production file:
React_app_base_url=./todos
Because we want json-server and our UI using the-same domain & port, so here we can just use relative path.
To use the variable in. env, we can do:
Const BASEURL == Async () = { return await fetch (BASEURL) = Response.json ());};
Update Package.json:
"Start": "Json-server--static/build Db.json", "dev": "React-scripts start",
We Change the original "start" to "Dev".
Because after "Build", there is a "build" folder, so-tell Json-server to server the build folder and use Db.json file A db.
After everything set up, just run:
Now
[React] Configure a React & Redux application for Production Deployment and Deploy to now