使用 nodejs 目录根目录中的 react build 文件夹和 index.js:
const path = require('path');
const express = require('express');
const app = express();
require('./startup/config')();
require('./startup/routes')(app);
require('./startup/db')();
require('./startup/validation')();
require('./startup/prod')(app);
app.use(express.static(path.join(__dirname, 'build')));
app.get('/*', (req, res) => {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
const port = process.env.PORT;
const server = require('./startup/socket')(app, port);
module.exports = server;
尝试部署时出现此错误
Loading failed for the <script> with source “https://www.example.com/static/js/runtime-main.0e11355c.js”.
Loading failed for the <script> with source “https://www.example.com/static/js/2.664acc69.chunk.js”.
Loading failed for the <script> with source “https://www.example.com/static/js/main.5603ef9c.chunk.js”.