问题描述
我在本地主机上具有以下配置。
const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');
// Config
const { routes } = require('./config.json');
const app = express();
for (route of routes) {
app.use(route.route,createProxyMiddleware({
target: route.address,pathRewrite: (path,req) => {
return path.split('/').slice(2).join('/');
}
})
);
}
app.listen(80,() => {
console.log('Proxy listening on port 80');
})
{
"routes": [
{
"route": "/project","address": "http://localhost:3000"
},{
"route": "/project2","address": "http://localhost:3001"
}
]
}
在project
文件夹中,我在client
中有create-react-app。当我在该文件夹中运行npm start时,按预期方式访问http://localhost:3000
。当我尝试访问http://localhost/project
时,它将反向代理到正确的文件夹,但不提供JS或CSS。
我已经浏览了多个论坛和教程,但无法完成这项工作。
有人可以帮忙吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)