surrealpatch/src/web/mod.rs

70 lines
1.3 KiB
Rust
Raw Normal View History

2020-06-29 15:36:01 +00:00
mod export;
mod head;
mod import;
mod key;
mod log;
mod root;
mod signin;
mod signup;
mod sql;
mod status;
mod sync;
mod version;
2021-03-29 15:43:37 +00:00
use anyhow::Error;
2020-06-29 15:36:01 +00:00
use std::net::SocketAddr;
use warp::Filter;
2021-03-29 15:43:37 +00:00
use uuid::Uuid;
const ID: &'static str = "Request-Id";
2020-06-29 15:36:01 +00:00
#[tokio::main]
pub async fn init(opts: &clap::ArgMatches) -> Result<(), Error> {
//
let adr = opts.value_of("bind").unwrap();
//
let adr: SocketAddr = adr.parse().expect("Unable to parse socket address");
let web = root::config()
// Version endpoint
.or(version::config())
// Status endpoint
.or(status::config())
// Signup endpoint
.or(signup::config())
// Signin endpoint
.or(signin::config())
// Export endpoint
.or(export::config())
// Import endpoint
.or(import::config())
// Backup endpoint
.or(sync::config())
// Endpoints for sql queries
.or(sql::config())
// Key for key queries
.or(key::config())
// End routes setup
;
let web = web.with(warp::compression::gzip());
2021-03-29 15:43:37 +00:00
let web = web.with(head::server());
2020-06-29 15:36:01 +00:00
let web = web.with(head::version());
2021-03-29 15:43:37 +00:00
let web = web.map(|reply| {
let val = Uuid::new_v4().to_string();
warp::reply::with_header(reply, ID, val)
});
2020-06-29 15:36:01 +00:00
let web = web.with(log::write());
2021-03-29 15:43:37 +00:00
2020-06-29 15:36:01 +00:00
info!("Starting web server on {}", adr);
warp::serve(web).run(adr).await;
Ok(())
}