Every time i try to send a request to the Heroku server, it hangs until the app crashes due to the R10 error which is the server not binding to the port given by Heroku. I have no idea why this is doing this. Here is my main class with a simple server set up for testing.
public static void main(String[] args) {
port(getHerokuAssignedPort());
get("/",(req,res) -> "Request Recived!");
}
static int getHerokuAssignedPort() {
ProcessBuilder processBuilder = new ProcessBuilder();
if (processBuilder.environment().get("PORT") != null) {
return Integer.parseInt(processBuilder.environment().get("PORT"));
}
return 4567; //return default port if heroku-port isn't set (i.e. on localhost)
}
Here is my procfile:
web: java -jar attendance-bot.jar
Like I said, the program hangs until it crashes due to a port not being bound.
尝试使用Integer.valueOf(System.getenv("PORT"))
获得端口号。
It was my mistake. I forgot to build the jar when pushing to the heroku server.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.