I have a React app made with create-react-app which I am trying to run on an express server. It works fine when running npm start but when running npm run build and then serve -g build I can only connect to port 5000 on localhost and not 8080 which I set up in the express server.
server.js
const express = require('express');
const jsonServer = require('json-server')
const path = require('path');
const app = express();
app.use(express.static(path.join(__dirname, 'build')));
app.get('/ping', function (req, res) {
return res.send('pong');
});
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
app.get('/remote', function (req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
app.use('/api', jsonServer.router('./src/config.json'));
app.listen(process.env.PORT || 8080);
I have also setup my proxy and main
package.json
"main": "server.js",
"proxy": "http://localhost:8080",
How can I make this work?