【发布时间】:2018-09-29 02:12:35
【问题描述】:
我正在尝试从节点服务器提供 index.html 文件,但我收到此错误 "localhost/:1 Refused to execute the script from 'http://localhost:3001/assets/app.js' 因为它的 MIME 类型 ('text/html' ) 不可执行,并且启用了严格的 MIME 类型检查。”
index.html
<!DOCTYPE html>
<html>
<head>
<title>Common JS Example</title>
</head>
<body>
<h1>CommonJS</h1>
<script type="text/javascript" src="./assets/app.js"></script>
</body>
</html>
server.js
var express = require('express');
var path = require('path');
var app = express();
app.use(express.static(path.resolve(__dirname, "assets")));
app.get('/',function(req,res){
res.sendFile(path.resolve(__dirname, "./index.html"))
})
app.listen(3001, () => console.log('Example app listening on port 3001!'))
app.js
console.log('hiiii')
【问题讨论】:
-
对不起,我知道这是一个非常幼稚的问题,但我最近开始研究 nodeJS
标签: javascript node.js