I started the responsive application using create-react-app and ran the npm run eject
script to access all the files. Then I installed the expressed and created server.js
file, which is at the same level as the package.json
file
this is server.js
file contents:
const express = require('express'); const app = express; app.set('port', 3031); if(process.env.NODE_ENV === 'production') { app.use(express.static('build')); } app.listen(app.get('port'), () => { console.log(`Server started at: http://localhost:${app.get('port')}/`); })
Nothing crazy here, just a setup for future api proxies where I need to use secrets, and since I don't want to reveal my api.
after that I added the file "proxy": "http://localhost:3001/"
to my package.json
. I'm stuck now, because I need to figure out how to properly start my server and use this server.js
file in development mode and then in production.
Ideally, it would be nice if we could use more than one proxy, i.e. /api
and /api2
source share