After repeated builds, I am unable to deploy my hello world actix app on Heroku.
I believe it has something to do with setting the port on the fly.
Right now I am doing this-
use actix_web::{web, App, HttpResponse, HttpServer, Responder};
async fn index() -> impl Responder {
HttpResponse::Ok().body("Hello world!")
}
async fn index2() -> impl Responder {
HttpResponse::Ok().body("Hello world again!")
}
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.route("/", web::get().to(index))
.route("/again", web::get().to(index2))
})
.bind("0.0.0.0:8088")?
.run()
.await
}
Any help here would be highly appreciated!
[SOLVED]:
Changed my code to:
use actix_web::{web, App, HttpResponse, HttpServer, Responder};
use std::env;
async fn index() -> impl Responder {
HttpResponse::Ok().body("Hello world!")
}
async fn index2() -> impl Responder {
HttpResponse::Ok().body("Hello world again!")
}
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
let HOST = env::var("HOST").expect("Host not set");
let PORT = env::var("PORT").expect("Port not set");
HttpServer::new(|| {
App::new()
.route("/", web::get().to(index))
.route("/again", web::get().to(index2))
})
.bind(format!("{}:{}", HOST, PORT))?
.run()
.await
}
And then configured the values in Heroku under "Settings".
2 Likes
system
Closed
3
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.