【发布时间】:2020-12-21 20:19:37
【问题描述】:
我有一个使用 create-react-app 制作的 React 应用程序,我试图在快速服务器上运行它。它在运行npm start 时工作正常,但是在运行npm run build 和serve -g build 时,我只能连接到本地主机上的5000 端口,而不是我在快速服务器中设置的8080。
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);
我还设置了代理和主服务器
package.json
"main": "server.js",
"proxy": "http://localhost:8080",
我怎样才能做到这一点?
【问题讨论】:
标签: node.js reactjs express npm