I have started a react application using create-react-app and ran the npm run eject
script to gain access to all files. I afterwards installed express and created server.js
file that sits on same level as package.json
file
these are 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 setting up for future api proxies where I need to use secrets and as I don't want to expose my api.
after this I added a "proxy": "http://localhost:3001/"
to my package.json
file. I am now stuck as I need to figure out how to start my server correctly and use this server.js
file in development mode and afterwards in production.
Ideally It would also be good if we could use more that one proxy i.e. /api
and /api2