Node.js 节点不提供从公用文件夹生成的响应
我试图为我的React构建提供服务,我将其放置在我的nodejs服务器的公用文件夹中,我从main.js启动我的nodejs服务器,因此文件结构如下:Node.js 节点不提供从公用文件夹生成的响应,node.js,reactjs,Node.js,Reactjs,我试图为我的React构建提供服务,我将其放置在我的nodejs服务器的公用文件夹中,我从main.js启动我的nodejs服务器,因此文件结构如下: -App --public ---index.html ---manifest.json --main.js app.use(express.static(path.join(__dirname, "public"))); app.get("/*", function (request, respons
-App
--public
---index.html
---manifest.json
--main.js
app.use(express.static(path.join(__dirname, "public")));
app.get("/*", function (request, response) {
response.sendFile(path.join(__dirname, "public", "index.html"));
});
这是我的舱单:
{
"short_name": "React App",
"name": "factoryio",
"start_url": "./",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
在我的main.js中,我尝试像这样为index.html提供服务:
-App
--public
---index.html
---manifest.json
--main.js
app.use(express.static(path.join(__dirname, "public")));
app.get("/*", function (request, response) {
response.sendFile(path.join(__dirname, "public", "index.html"));
});
我还尝试了不同的用法变体,使用/不使用斜杠,例如:
app.get("*", ...)
app.get("/", ...)
app.get("/*", ...)
以及:
我还尝试将以下选项添加到app.use:
app.use(
express.static(path.join(__dirname, "public"), { extensions: ["htm", "html", "json", "js", "css"], redirect: false })
);
也没有帮助
如果我尝试手动打开http://localhost:3000/manifest.json url,它不会打开,而是重定向到http://localhost:3000/manifest.json/ 在最后
客户端路由/admin也将我重定向到/admin/:http://localhost:3000/admin -> http://localhost:3000/admin/
使用当前代码优先代码在控制台中遇到的错误有:
localhost/:10 Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost:3000/static/css/2.af3c1da9.chunk.css".
localhost/:11 Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost:3000/static/css/main.c2ccd1c1.chunk.css".
2.6a24bec0.chunk.js:1 Uncaught SyntaxError: Unexpected token '<'
main.5370f0d7.chunk.js:1 Uncaught SyntaxError: Unexpected token '<'
manifest.json:1 Manifest: Line: 1, column: 1, Syntax error.