我有一个 express 应用,里面有一个 create-react-app。当用户转到根 url 时,我想显示 create-react-app 公共(public)文件夹中存在的 index.html。这是我在 express 应用程序中的 index.js 代码
const express = require("express");
const app = express();
app.get('/',function(req,res){
});
const PORT = process.env.PORT || 5000;
app.listen(PORT);
这是我的项目目录
最佳答案
你需要这一行:app.use(express.static('public'))
。看这里:https://expressjs.com/en/starter/static-files.html
关于javascript - 在 express 和 react 中用 index.html 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51064742/