surwiki/src/lib.rs

72 lines
1.5 KiB
Rust
Raw Permalink Normal View History

2022-04-03 23:03:03 +03:00
#![allow(clippy::into_iter_on_ref)]
#![allow(clippy::vec_init_then_push)]
2022-04-03 14:47:43 +03:00
#![recursion_limit = "128"]
// for diesel's infer_schema!
2022-04-03 14:47:43 +03:00
#[cfg(test)]
#[macro_use]
extern crate matches;
#[macro_use]
extern crate bart_derive;
#[macro_use]
extern crate codegen;
#[macro_use]
2022-04-03 23:03:03 +03:00
#[allow(clippy::useless_attribute)]
2022-04-03 14:47:43 +03:00
#[allow(deprecated)]
extern crate diesel_infer_schema;
#[macro_use]
extern crate diesel_migrations;
#[macro_use]
extern crate diesel;
#[macro_use]
extern crate hyper;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate maplit;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate serde_plain;
use std::net::{IpAddr, SocketAddr};
mod assets;
mod build_config;
mod db;
2017-11-16 17:38:45 +03:00
mod merge;
mod mimes;
mod models;
mod rendering;
mod resources;
mod schema;
mod site;
mod state;
mod theme;
mod web;
mod wiki_lookup;
2022-04-03 14:47:43 +03:00
pub fn main(
db_file: String,
bind_host: IpAddr,
bind_port: u16,
trust_identity: bool,
) -> Result<(), Box<dyn std::error::Error>> {
let db_pool = db::create_pool(db_file)?;
let cpu_pool = futures_cpupool::CpuPool::new_num_cpus();
let state = state::State::new(db_pool, cpu_pool);
let lookup = wiki_lookup::WikiLookup::new(state, trust_identity);
2022-04-03 14:47:43 +03:00
let server = hyper::server::Http::new()
.bind(&SocketAddr::new(bind_host, bind_port), move || {
Ok(site::Site::new(lookup.clone(), trust_identity))
})?;
println!("Listening on http://{}", server.local_addr().unwrap());
server.run()?;
Ok(())
}