reactjs - 将所有模块组合在一页上时“无法获取/”?
问题描述
伙计们,当我在一页上呈现所有 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.
大佬们有什么意见吗,谢谢
解决方案
服务点(在 URL 中):/<SOME_ID>
app.use('/:id', express.static(path.join(__dirname, '../public')));
服务点(在 URL 中):/
app.use('/', express.static(path.join(__dirname, '../public')));
我希望这有帮助。
推荐阅读
- javascript - 如何将 js 文件读取器结果保存到变量中以供将来使用?
- php - ErrorException(E_ERROR)试图在 laravel 5.5 中获取非对象的属性“名称”
- ios - iOS - AVPlayer 不播放 mov 文件
- python - 一个班轮 - 嵌套 for 循环
- r - 使用不同类的变量重新编码数据集
- python - 将一个文件合并到组中的另一个文件
- java - 如何将时间戳转换为日期
- c# - 我正在尝试从尚未使用 LINQ 创建具有特定属性的附加对象的用户列表中创建新的用户列表
- c# - 无法连接到 Azure SignalR Hub
- python - 如何将 lmplot 图叠加在一起?