【发布时间】:2021-01-24 11:54:16
【问题描述】:
所以我有一个文件要从我的计算机托管,并且出于各种原因我希望能够在端口上监听。我正在使用
const port = [number]
http.createServer((req, res) => {
let responseCode = 404;
let content = '404 Error';
const urlObj = url.parse(req.url, true);
if (urlObj.query.code) {
const accessCode = urlObj.query.code;
}
if (urlObj.pathname === '/') {
responseCode = 200;
content = fs.readFileSync('./index.html');
}
res.writeHead(responseCode, {
'content-type': 'text/html;charset=utf-8',
});
res.write(content);
res.end();
})
.listen(port);
所有这些好东西都让我可以拥有一个本地文件http://localhost:[number]。但是,我不确定如何使用相同的方法在在线网站上进行托管,在这种方法中,我将代码上传到网站,然后让网站从我的计算机启动(使用创建服务器)。有谁知道如何基本上创建一个不是私有/本地的服务器,而是公共的(是的,我可以使用网络主机)。
【问题讨论】:
-
什么?!这是一个编码问题还是“如何”将服务器“发布”到 interweebz ?