libreddit/src/main.rs

54 lines
1.2 KiB
Rust
Raw Normal View History

2020-10-25 21:25:59 +01:00
// Import Crates
2020-11-19 01:31:46 +01:00
use actix_web::{get, App, HttpResponse, HttpServer};
use std::fs;
2020-10-25 21:25:59 +01:00
// Reference local files
mod popular;
mod post;
mod subreddit;
2020-10-26 04:57:19 +01:00
mod user;
2020-10-25 21:25:59 +01:00
// Create Services
#[get("/style.css")]
2020-11-19 01:31:46 +01:00
async fn style() -> HttpResponse {
let file = fs::read_to_string("static/style.css").expect("ERROR: Could not read style.css");
HttpResponse::Ok().content_type("text/css").body(file)
2020-10-25 21:25:59 +01:00
}
2020-11-21 04:33:38 +01:00
#[get("/robots.txt")]
async fn robots() -> HttpResponse {
let file = fs::read_to_string("static/robots.txt").expect("ERROR: Could not read robots.txt");
HttpResponse::Ok().body(file)
}
2020-10-25 21:25:59 +01:00
#[get("/favicon.ico")]
async fn favicon() -> HttpResponse {
HttpResponse::Ok().body("")
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
2020-10-26 04:57:19 +01:00
// start http server
2020-11-16 23:45:20 +01:00
println!("Running Libreddit on 0.0.0.0:8080!");
2020-11-19 03:50:59 +01:00
2020-10-25 21:25:59 +01:00
HttpServer::new(|| {
2020-10-26 04:57:19 +01:00
App::new()
// GENERAL SERVICES
.service(style)
.service(favicon)
2020-11-21 04:33:38 +01:00
.service(robots)
2020-10-26 04:57:19 +01:00
// POST SERVICES
.service(post::short)
.service(post::page)
// SUBREDDIT SERVICES
.service(subreddit::page)
// POPULAR SERVICES
.service(popular::page)
// USER SERVICES
.service(user::page)
})
2020-11-16 23:45:20 +01:00
.bind("0.0.0.0:8080")?
2020-10-26 04:57:19 +01:00
.run()
.await
}