嗨,我正在尝试学习节点的一个小项目,我有一个节点获取请求,女巫读取主页 HTML 文件然后发送它,
在 HTML 站点上,我有一个脚本标签(类型 = 模块),并且在脚本的最开始,我正在导入 lit-HTML 模块,但它会将整个脚本标签缝合起来,我该如何修复它?节点代码:
if (req.method === "GET") { console.log(req.url); switch (req.url) { case '/' : res.writeHead(200,{"Content-Type": "text/html"}) fs.createReadStream("index.html","UTF-8").pipe(res); break;
case '/lit-html.js': var file = fs.readFileSync('lib/lit-html.mjs','UTF-8') res.writeHead(200,{"Content-Type": "application/javascript"}) res.end(file); break;
这是在 index.html 里面
<script type="module" src="localhost:8000/lit-html.js"></script> <script> import {html, render} from 'localhost:8000/lit-html.js';
这是在节点
if (req.method === "GET") { console.log(req.url); switch (req.url) { case '/' : res.writeHead(200,{"Content-Type": "text/html"}) fs.createReadStream("index.html","UTF-8").pipe(res); break;
case '/lit-html.js':
var file = fs.readFileSync('lib/lit-html.mjs','UTF-8')
res.writeHead(200,{"Content-Type": "application/javascript"})
res.end(file);
休息;
这是在 index.html 里面
<script type="module" src="localhost:8000/lit-html.js"></script> <script> import {html, render} from 'localhost:8000/lit-html.js';