mirror of
https://github.com/neon-mmd/websurfx.git
synced 2024-11-22 22:18:23 -05:00
36 lines
1.2 KiB
Rust
36 lines
1.2 KiB
Rust
|
use websurfx::server::routes;
|
||
|
|
||
|
use actix_files as fs;
|
||
|
use actix_web::{web, App, HttpServer};
|
||
|
use handlebars::Handlebars;
|
||
|
|
||
|
// The function that launches the main server and handle routing functionality
|
||
|
#[actix_web::main]
|
||
|
async fn main() -> std::io::Result<()> {
|
||
|
let mut handlebars: Handlebars = Handlebars::new();
|
||
|
|
||
|
handlebars
|
||
|
.register_templates_directory(".html", "./public/templates")
|
||
|
.unwrap();
|
||
|
|
||
|
let handlebars_ref: web::Data<Handlebars> = web::Data::new(handlebars);
|
||
|
|
||
|
HttpServer::new(move || {
|
||
|
App::new()
|
||
|
.app_data(handlebars_ref.clone())
|
||
|
// Serve images and static files (css and js files).
|
||
|
.service(fs::Files::new("/static", "./public/static").show_files_listing())
|
||
|
.service(fs::Files::new("/images", "./public/images").show_files_listing())
|
||
|
.service(routes::robots_data) // robots.txt
|
||
|
.service(routes::index) // index page
|
||
|
.service(routes::search) // search page
|
||
|
.service(routes::about) // about page
|
||
|
.service(routes::settings) // settings page
|
||
|
.default_service(web::route().to(routes::not_found)) // error page
|
||
|
})
|
||
|
// Start server on 127.0.0.1:8080
|
||
|
.bind(("127.0.0.1", 8080))?
|
||
|
.run()
|
||
|
.await
|
||
|
}
|