【发布时间】:2018-09-01 03:30:54
【问题描述】:
我的 GET 请求试图在我的 routes.js 文件中加载一个 html 页面
app.get('/api/testresult', (req, res) => {
res.sendFile('/path/myfile.html');
});
另外,在我的 server.js 中,我有以下内容
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const path = require('path');
const port = 8000;
app.use('/', express.static(path.join(__dirname, './app/report')));
require('./app/routes')(app, {});
app.listen(port, () => {
console.log('Server running on ' + port);
});
但是,当我尝试进行 GET 调用时,它会在浏览器控制台上引发错误
localhost/:1 Refused to apply style from
'http://localhost:8000/api/testresult/assets/app.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
localhost/:2 GET http://localhost:8000/api/testresult/assets/app.js 404 (Not Found)
localhost/:1 Refused to execute script from 'http://localhost:8000/api/testresult/assets/app.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
我的文件结构是
MyApp
app
—report
—assets
—app.css
—app.js
—my file.html
—routes
—index.js
—routes.js
node_modules
package.json
server.js
我在这里错过了什么?
【问题讨论】:
-
那么,对于这个错误
GET http://localhost:8000/api/testresult/assets/app.js 404 (Not Found),app.js在您的文件系统中的位置是什么? -
如果您试图显示文件层次结构,我们无法在 cmets 中真正读取它。请使用“编辑”链接将该信息添加到问题的末尾,以便您可以适当地对其进行格式化。
-
是的,这很难。在 cmets 中添加了
标签: javascript html express