Initial commit
This commit is contained in:
33
src/main.rs
Normal file
33
src/main.rs
Normal file
@ -0,0 +1,33 @@
|
||||
use actix_web::middleware::Logger;
|
||||
use actix_web::{web, App, HttpResponse, HttpServer};
|
||||
use log::LevelFilter;
|
||||
use rand::Rng;
|
||||
|
||||
async fn home() -> HttpResponse {
|
||||
log::info!("Successfully found the port!");
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/html")
|
||||
.body(include_str!("../assets/home.html"))
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
env_logger::Builder::new()
|
||||
.filter_module("actix_server::server", LevelFilter::Warn)
|
||||
.filter(None, LevelFilter::Info)
|
||||
.init();
|
||||
|
||||
log::info!("Choosing a random port to start...");
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
let port: u16 = 80 + rng.random::<u16>() % 10000;
|
||||
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
.wrap(Logger::default())
|
||||
.route("/", web::get().to(home))
|
||||
})
|
||||
.bind(("127.0.0.1", port))?
|
||||
.run()
|
||||
.await
|
||||
}
|
Reference in New Issue
Block a user