首页 > 解决方案 > 将所有模块组合在一页上时“无法获取/”?

问题描述

伙计们,当我在一页上呈现所有 React 模块时,我遇到了问题。

所有 3 个模块在单独的端口上都可以正常工作。但是当我使用这样的方法组合它们时

    <!DOCTYPE html>
  <html lang="en">
  <head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="/style.css">
    <title>FEC Demo</title>
  </head>
  <body>
    <div id="app"></div>

    <script src="http://localhost:3000/bundle.js"></script>
    <script src="http://localhost:3001/b5/undle.js"></script>
    <script src="http://localhost:3009/bundle.js"></script>

  </body>
</html>


const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');

var port = 4567;
var app = express();

app.use(bodyParser.json());
app.use('/:id', express.static(path.join(__dirname, '../public')));

app.listen(port, () => console.log(`server listening at http://localhost:${port}



当我将它们组合到新页面时,它会给我一个错误


GET http://localhost:4567/ 404 (Not Found)

Refused to load the image 'http://localhost:4567/favicon.ico' because it violates the following Content Security Policy directive: "default-src 'none'". Note that 'img-src' was not explicitly set, so 'default-src' is used as a fallback.


大佬们有什么意见吗,谢谢

标签: reactjsexpressproxyget

解决方案


服务点(在 URL 中):/<SOME_ID>

app.use('/:id', express.static(path.join(__dirname, '../public')));

服务点(在 URL 中):/

app.use('/', express.static(path.join(__dirname, '../public')));

我希望这有帮助。


推荐阅读