diff options
| author | Ellie Huxtable <e@elm.sh> | 2021-03-21 20:04:39 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-21 20:04:39 +0000 |
| commit | c9579cb9ca2a6a165d10f128e0af1dfd372e0c03 (patch) | |
| tree | 1d4feecb422aae3cde1cc7cad54ccc73b2dae410 /src/remote/server.rs | |
| parent | Add TUI, resolve #19, #17, #16 (#21) (diff) | |
| download | atuin-c9579cb9ca2a6a165d10f128e0af1dfd372e0c03.zip | |
Implement server (#23)
* Add initial database and server setup
* Set up all routes, auth, etc
* Implement sessions, password auth, hashing with argon2, and history storage
Diffstat (limited to '')
| -rw-r--r-- | src/remote/server.rs | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/src/remote/server.rs b/src/remote/server.rs index bc1dc2bd..4409f646 100644 --- a/src/remote/server.rs +++ b/src/remote/server.rs @@ -1,8 +1,42 @@ -#[get("/")] -const fn index() -> &'static str { - "Hello, world!" -} +use rocket::config::{Config, Environment, LoggingLevel, Value}; + +use std::collections::HashMap; + +use crate::remote::database::establish_connection; +use crate::settings::Settings; + +use super::database::AtuinDbConn; + +// a bunch of these imports are generated by macros, it's easier to wildcard +#[allow(clippy::clippy::wildcard_imports)] +use super::views::*; + +#[allow(clippy::clippy::wildcard_imports)] +use super::auth::*; + +embed_migrations!("migrations"); + +pub fn launch(settings: &Settings) { + let mut database_config = HashMap::new(); + let mut databases = HashMap::new(); + + database_config.insert("url", Value::from(settings.remote.db.url.clone())); + databases.insert("atuin", Value::from(database_config)); + + let connection = establish_connection(settings); + embedded_migrations::run(&connection).expect("failed to run migrations"); + + let config = Config::build(Environment::Production) + .address("0.0.0.0") + .log_level(LoggingLevel::Normal) + .port(8080) + .extra("databases", databases) + .finalize() + .unwrap(); -pub fn launch() { - rocket::ignite().mount("/", routes![index]).launch(); + let app = rocket::custom(config); + app.mount("/", routes![index, register, add_history, login]) + .attach(AtuinDbConn::fairing()) + .register(catchers![internal_error, bad_request]) + .launch(); } |
