【发布时间】:2021-08-18 10:27:27
【问题描述】:
我正在尝试配置一个 nodeJS express 应用程序,该应用程序处理一个 react 静态构建,以便从我的 VPS (nginx) 内的某个位置运行。
到目前为止,我已经设法像这样配置位置:
- 在 webpack 构建中添加了路径:
output: {
path: path.join(__dirname, '/client/public/dist/'),
filename: 'main.js',
publicPath: "/location/",
},
- 添加了快速服务器的路径:
app.use("/location/", express.static(path.join(__dirname, './client/public/dist/')))
-
将位置添加到反应路由器,添加到每个路由
-
将位置添加到 nginx proxy_pass:
location /location{
proxy_pass http://localhost:5002/location;
}
我面临的问题是,如果我有子路径(例如 /location/page1),如果我刷新浏览器,我会收到错误 cannot get /location/page1
我尝试将快递服务器修改为app.use("/location/*", )或 app.use("*"),
但我得到 Uncaught SyntaxError: Unexpected token '
这是 index.html 的问题吗?有没有更简单的方法从定位路径运行应用程序?
【问题讨论】: