在尝试从Heroku运行blue-jay / blueprint时,我无法绑定到.json文件中指定的端口80,因为Heroku似乎动态设置端口。
使用os.Getenv(“PORT”)似乎不是一个选项,因为.json是一个静态文件。
HTTPPort:env.json
"Server": {
"Hostname": "",
"UseHTTP": true,
"UseHTTPS": false,
"RedirectToHTTPS": false,
"HTTPPort": 80,
"HTTPSPort": 443,
"CertFile": "tls/server.crt",
"KeyFile": "tls/server.key"
},
返回服务器错误:
server.go:56: listen tcp :80: bind: permission denied
来源:
https://github.com/blue-jay/blueprint/blob/master/env.json.example
https://github.com/blue-jay/blueprint
处理此问题的适当方法是什么?
答案 0 :(得分:2)
是的,你不能在Heroku上设置端口。你必须处理他们的港口。我建议您在运行服务器之前修改port := os.Getenv("PORT")
if port == "" {
log.Fatal("$PORT must be set")
}
config.Server.HTTPPort, _ = strconv.Atoi(port)
// Start the HTTP and HTTPS listeners
server.Run(
handler, // HTTP handler
handler, // HTTPS handler
config.Server, // Server settings
)
BETWEEN