-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
54 lines (50 loc) · 1.33 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use actix::Actor;
use actix_web::{middleware, web, App, HttpServer};
use clap::Clap;
use rand::rngs::ThreadRng;
mod app;
use app::AppState;
mod cli;
use cli::Opts;
mod handlers;
use handlers::ApplicationState;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let opts: Opts = Opts::parse();
if opts.coin_probs.len() < 3 {
println!("At least 3 coin probabilities are required");
std::process::exit(1);
}
if opts.verbose {
std::env::set_var("RUST_LOG", "actix_web=debug");
env_logger::init();
println!("Starting server.");
}
let app_addr =
AppState::new(ThreadRng::default(), opts.coin_probs.clone(), opts.verbose).start();
HttpServer::new(move || {
App::new()
.wrap(middleware::Logger::default())
.data(ApplicationState::new(
ThreadRng::default(),
app_addr.clone(),
opts.coin_probs.clone(),
))
.service(handlers::set_cookie)
.route("/game/", web::get().to(handlers::game_html))
.service(handlers::game_files)
.service(handlers::game_style)
.service(handlers::game_audio)
.service(handlers::flip)
.service(handlers::flush)
.service(handlers::redirect)
.service(handlers::index)
.service(handlers::index_files)
.service(handlers::index_style)
.service(handlers::count)
.default_service(web::get().to(handlers::not_found))
})
.bind("0.0.0.0:8080")?
.run()
.await
}