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;
|
2022-05-10 07:17:47 +00:00
|
|
|
mod index;
|
2020-06-29 15:36:01 +00:00
|
|
|
mod key;
|
|
|
|
mod log;
|
2022-02-05 23:06:16 +00:00
|
|
|
mod output;
|
2022-07-04 00:01:24 +00:00
|
|
|
mod rpc;
|
2022-05-10 07:29:25 +00:00
|
|
|
mod session;
|
2020-06-29 15:36:01 +00:00
|
|
|
mod signin;
|
|
|
|
mod signup;
|
|
|
|
mod sql;
|
|
|
|
mod status;
|
|
|
|
mod sync;
|
|
|
|
mod version;
|
|
|
|
|
2022-07-04 00:01:24 +00:00
|
|
|
use crate::cli::CF;
|
2022-02-16 23:45:23 +00:00
|
|
|
use crate::err::Error;
|
2022-01-13 17:36:41 +00:00
|
|
|
use warp::Filter;
|
2021-03-29 15:43:37 +00:00
|
|
|
|
2022-07-04 00:01:24 +00:00
|
|
|
pub async fn init() -> Result<(), Error> {
|
2022-02-17 07:39:40 +00:00
|
|
|
// Setup web routes
|
2022-05-10 07:17:47 +00:00
|
|
|
let net = index::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-07-04 00:01:24 +00:00
|
|
|
// RPC query endpoint
|
|
|
|
.or(rpc::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-17 07:39:40 +00:00
|
|
|
// Enable response compression
|
2022-02-13 23:33:52 +00:00
|
|
|
let net = net.with(warp::compression::gzip());
|
2022-02-17 07:39:40 +00:00
|
|
|
// Specify a generic version header
|
2022-02-13 23:33:52 +00:00
|
|
|
let net = net.with(head::version());
|
2022-02-17 07:39:40 +00:00
|
|
|
// Specify a generic server header
|
|
|
|
let net = net.with(head::server());
|
|
|
|
// Log all requests to the console
|
2022-02-13 23:33:52 +00:00
|
|
|
let net = net.with(log::write());
|
2020-06-29 15:36:01 +00:00
|
|
|
|
2022-05-10 07:17:47 +00:00
|
|
|
// Get local copy of options
|
|
|
|
let opt = CF.get().unwrap();
|
|
|
|
|
|
|
|
info!("Starting web server on {}", &opt.bind);
|
2020-06-29 15:36:01 +00:00
|
|
|
|
2022-05-10 07:22:04 +00:00
|
|
|
if let (Some(crt), Some(key)) = (&opt.crt, &opt.key) {
|
|
|
|
warp::serve(net).tls().cert_path(crt).key_path(key).run(opt.bind).await
|
|
|
|
} else {
|
|
|
|
warp::serve(net).run(opt.bind).await
|
|
|
|
};
|
2020-06-29 15:36:01 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|