createServer();function createServer(){var http = nodeRequire("http"); http.createServer(function(request, response) {let path = request.url; response.writeHead(200, {"Content-Type": "text/html"}); let fs = nodeRequire("fs"); let data = fs.readFileSync(app_dir+path); response.write(data.toString()); response.end();}).listen(8888);}
就像這樣,輸出一個html文件,跟正常訪問一樣,不過遇到css、js什么都要自己判斷。應(yīng)該有現(xiàn)成的輪子可用了,推薦一個吧?