javascript - 在 express 和 react 中用 index.html 响应

标签 javascript reactjs express create-react-app

我有一个 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/

相关文章:

javascript - react forwardRef : ref and other props

javascript - 如何使用 Framer Motion 沿路径移动 SVG 对象?

javascript - Express.js,我新添加的路由出现 404(未找到)错误

javascript - Express 页面根据一天中的时间变化

node.js - 哪个是好的做法?在数据库中公开主键还是使用其他唯一键查找用户?

javascript - jquery mobile 中的旋转木马图片库

javascript - Jquery .val() 函数不适用于全局范围

json - 服务器未将 JSON 从 Express 返回到 React(代理)

javascript - 将内部 div 的宽度设置为容器的宽度

javascript - 在 NVD3 和 ClojureScript 中设置图表的静态刻度数