2022-01-13 17:36:41 +00:00
|
|
|
mod conf;
|
2020-06-29 15:36:01 +00:00
|
|
|
mod export;
|
2022-01-14 17:13:44 +00:00
|
|
|
mod fail;
|
2020-06-29 15:36:01 +00:00
|
|
|
mod head;
|
|
|
|
mod import;
|
|
|
|
mod key;
|
|
|
|
mod log;
|
2022-02-05 23:06:16 +00:00
|
|
|
mod output;
|
2020-06-29 15:36:01 +00:00
|
|
|
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;
|
2021-03-29 15:43:37 +00:00
|
|
|
use uuid::Uuid;
|
2022-01-13 17:36:41 +00:00
|
|
|
use warp::Filter;
|
2021-03-29 15:43:37 +00:00
|
|
|
|
|
|
|
const ID: &'static str = "Request-Id";
|
2020-06-29 15:36:01 +00:00
|
|
|
|
|
|
|
#[tokio::main]
|
2022-02-13 23:33:52 +00:00
|
|
|
pub async fn init(bind: &str) -> Result<(), Error> {
|
2020-06-29 15:36:01 +00:00
|
|
|
//
|
2022-02-13 23:33:52 +00:00
|
|
|
let adr: SocketAddr = bind.parse().expect("Unable to parse socket address");
|
|
|
|
|
|
|
|
let net = root::config()
|
2020-06-29 15:36:01 +00:00
|
|
|
// 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())
|
2022-01-13 17:36:41 +00:00
|
|
|
// SQL query endpoint
|
2020-06-29 15:36:01 +00:00
|
|
|
.or(sql::config())
|
2022-01-13 17:36:41 +00:00
|
|
|
// API query endpoint
|
2020-06-29 15:36:01 +00:00
|
|
|
.or(key::config())
|
2022-01-14 17:13:44 +00:00
|
|
|
// Catch all errors
|
|
|
|
.recover(fail::recover)
|
2020-06-29 15:36:01 +00:00
|
|
|
// End routes setup
|
|
|
|
;
|
|
|
|
|
2022-02-13 23:33:52 +00:00
|
|
|
let net = net.with(warp::compression::gzip());
|
2020-06-29 15:36:01 +00:00
|
|
|
|
2022-02-13 23:33:52 +00:00
|
|
|
let net = net.with(head::server());
|
2021-03-29 15:43:37 +00:00
|
|
|
|
2022-02-13 23:33:52 +00:00
|
|
|
let net = net.with(head::version());
|
2020-06-29 15:36:01 +00:00
|
|
|
|
2022-02-13 23:33:52 +00:00
|
|
|
let net = net.map(|reply| {
|
2021-03-29 15:43:37 +00:00
|
|
|
let val = Uuid::new_v4().to_string();
|
2022-01-13 17:36:41 +00:00
|
|
|
warp::reply::with_header(reply, ID, val)
|
|
|
|
});
|
2020-06-29 15:36:01 +00:00
|
|
|
|
2022-02-13 23:33:52 +00:00
|
|
|
let net = net.with(log::write());
|
2020-06-29 15:36:01 +00:00
|
|
|
|
|
|
|
info!("Starting web server on {}", adr);
|
|
|
|
|
2022-02-13 23:33:52 +00:00
|
|
|
warp::serve(net).run(adr).await;
|
2020-06-29 15:36:01 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|