If the react app is to be served from the node.js server, simply send each app's index.html
:
app.get('/admin', (req, res) => {
res.sendFile('admin_app/index.html');
});
app.get('/', (req, res) => {
res.sendFile('public_app/index.html');
});
If those files are served from a different process on the same machine you will have to proxy the requests:
const httpProxy = require('http-proxy');
const proxy = httpProxy.createServer({});
app.get('/admin', (req, res) => {
proxy.web(req, res, { target: 'http://localhost:3006/admin' });
});
app.get('/', (req, res) => {
proxy.web(req, res, { target: 'http://localhost:3006/' });
});
Redirects would also work, as long as the process at 127.0.0.1:3006
listens on all public addresses. But a redirect includes that the users browser navigates to a different URL. E.g. if your node.js server was running at example.com
(i.e. port 80, which the browser omits) and redirects to the other process, the browser would now show example.com:3006
. By proxying the request, the URL will stay on example.com
.