问题描述
我有一个简单的纯 node.js 服务器,它根据请求发回 html 页面。 在我的 html 页面中,我连接了 js 文件。 当我提出请求时,我得到响应 html 页面,但没有响应 js 文件。 在我的控制台中出现错误。
Uncaught SyntaxError: Unexpected token '<'
我的 node.js 服务器文件:
const http = require('http');
const fs = require('fs');
http.createServer(function (req,res) {
res.writeHead(200,{'Content-Type': 'text/html',});
fs.readFile('index.html',function(err,data){
if(err){
return console.log(err);
}
res.end(data);
});
}).listen(8080);
console.log('Server is running on Port: 8080');
我的 html 文件:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>here</h1>
<script src="./app.js"></script>
</body>
</html>
关于如何使用纯 js 根据请求发送多个文件的任何建议?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)