2020-10-26 09:25:59 +13:00
|
|
|
// Import Crates
|
|
|
|
use actix_files::NamedFile;
|
2020-10-26 16:57:19 +13:00
|
|
|
use actix_web::{get, App, HttpResponse, HttpServer, Result};
|
2020-10-26 09:25:59 +13:00
|
|
|
|
|
|
|
// Reference local files
|
|
|
|
mod popular;
|
|
|
|
mod post;
|
|
|
|
mod subreddit;
|
2020-10-26 16:57:19 +13:00
|
|
|
mod user;
|
2020-10-26 09:25:59 +13:00
|
|
|
|
|
|
|
// Create Services
|
|
|
|
#[get("/style.css")]
|
|
|
|
async fn style() -> Result<NamedFile> {
|
|
|
|
let file = NamedFile::open("static/style.css");
|
|
|
|
Ok(file?)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/favicon.ico")]
|
|
|
|
async fn favicon() -> HttpResponse {
|
|
|
|
HttpResponse::Ok().body("")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_web::main]
|
|
|
|
async fn main() -> std::io::Result<()> {
|
2020-10-26 16:57:19 +13:00
|
|
|
// start http server
|
2020-11-17 11:45:20 +13:00
|
|
|
println!("Running Libreddit on 0.0.0.0:8080!");
|
2020-10-26 09:25:59 +13:00
|
|
|
HttpServer::new(|| {
|
2020-10-26 16:57:19 +13:00
|
|
|
App::new()
|
|
|
|
// GENERAL SERVICES
|
|
|
|
.service(style)
|
|
|
|
.service(favicon)
|
|
|
|
// 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-17 11:45:20 +13:00
|
|
|
.bind("0.0.0.0:8080")?
|
2020-10-26 16:57:19 +13:00
|
|
|
.run()
|
|
|
|
.await
|
|
|
|
}
|