【发布时间】:2020-11-07 11:56:33
【问题描述】:
我的网站地址是http://www.aboutsamyuen.com:8080/index.html
但是,如何在没有端口范围和http://www.aboutsamyuen.com 的情况下访问页面
仅,这意味着当我在浏览器中输入此链接时,它将显示 Hello World。
我正在使用 aws 服务,这是我在 server.js 中的代码:
var http = require('http');
var fs = require('fs');
var url = require('url');
http.createServer( function (request, response) {
var pathname = url.parse(request.url).pathname;
console.log("Trying to find '" + pathname.substr(1) + "'...");
fs.readFile(pathname.substr(1), function (err, data) {
if (err) {
response.writeHead(404, {'Content-Type': 'text/html'});
response.write("ERROR: Cannot find '" + pathname.substr(1) + "'.");
console.log("ERROR: Cannot find '" + pathname.substr(1) + "'.");
} else {
console.log("Found '" + pathname.substr(1) + "'.");
response.writeHead(200, {'Content-Type': 'text/html'});
response.write(data.toString());
}
response.end();
});
}).listen(8080, '0.0.0.0');
由于我对网络不熟悉,应该如何修改。
【问题讨论】:
标签: http web networking server