我想运行一个非常简单的HTTP服务器.每个GET请求都example.com应该index.html提供给它,但作为常规HTML页面(即,与您阅读普通网页时相同的体验).
使用下面的代码,我可以阅读的内容index.html.我如何index.html作为常规网页?
var http = require('http');
var fs = require('fs');
var index = fs.readFileSync('index.html');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end(index);
}).listen(9615);
Run Code Online (Sandbox Code Playgroud)
下面的一个建议很复杂,需要我为get我想要使用的每个资源(CSS,JavaScript,图像)文件写一行.
如何使用一些图像,CSS和JavaScript提供单个HTML页面?
我正在开发一个使用Web worker的项目.
在我的脑子部分,我有这个代码:
var worker = new Worker("worker.js");
// More code
Run Code Online (Sandbox Code Playgroud)
这在Safari中运行良好,但Chrome报告以下错误:
Uncaught SecurityError: Failed to create a worker: script at '(path)/worker.js' cannot be accessed from origin 'null'.
为什么这在Safari中完美运行而不是Chrome?我该如何解决?
谢谢.