gpt4 book ai didi

javascript - 无法在 Express JS 应用程序上设置 IP 地址

转载 作者:行者123 更新时间:2023-12-03 01:26:19 24 4
gpt4 key购买 nike

尝试在 Express 中测试端点,但不断收到 404 错误。

var express = require("express")
var app = express()
//var http = require('http').Server(app)
app.get('/', function(req,res){

res.send('ok from end point')
})
var port = process.env.PORT|| 8080
var localhost = 'someLocalHost.med.gov'
console.log({'localhost':localhost,
'post':port})
//
app.listen(port,localhost,function(err){

if (err){
console.log('err')
}
else {
console.log('Listening')
}
})
当我去 http://someLocalHost.med.gov:8080/我收到 404 错误

最佳答案

本地主机指的是127.0.0.1。您不能只在您想要的任何地址上启动服务器。如果您想覆盖localhost,您可以考虑修改您的 HOSTS file locally to setup an alias for localhost.

关于javascript - 无法在 Express JS 应用程序上设置 IP 地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51528594/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com