我想运行一个非常简单的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页面?