diff options
| author | morguldir <morguldir@protonmail.com> | 2022-07-26 09:05:34 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-26 08:05:34 +0100 |
| commit | 0c5e250800f1b8f50ea832bf414a5a7cdfe944a4 (patch) | |
| tree | 9ee6802b12d0400d34c3d07f484d88c081d146a1 /atuin-server/src/router.rs | |
| parent | Add kubernetes instructions and manifests (#427) (diff) | |
| download | atuin-0c5e250800f1b8f50ea832bf414a5a7cdfe944a4.zip | |
Add support for prepending a path to all routes for the server (#484)
* Add support for prepending a path to all routes
* Don't nest if there is no path provided
Co-authored-by: Conrad Ludgate <oon@conradludgate.com>
* Change the default for the path variable
* run cargo-fmt
Co-authored-by: Conrad Ludgate <oon@conradludgate.com>
Diffstat (limited to 'atuin-server/src/router.rs')
| -rw-r--r-- | atuin-server/src/router.rs | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/atuin-server/src/router.rs b/atuin-server/src/router.rs index 9b525e05..08eea996 100644 --- a/atuin-server/src/router.rs +++ b/atuin-server/src/router.rs @@ -57,7 +57,7 @@ async fn teapot() -> impl IntoResponse { (http::StatusCode::IM_A_TEAPOT, "☕") } pub fn router(postgres: Postgres, settings: Settings) -> Router { - Router::new() + let routes = Router::new() .route("/", get(handlers::index)) .route("/sync/count", get(handlers::history::count)) .route("/sync/history", get(handlers::history::list)) @@ -65,12 +65,19 @@ pub fn router(postgres: Postgres, settings: Settings) -> Router { .route("/history", post(handlers::history::add)) .route("/user/:username", get(handlers::user::get)) .route("/register", post(handlers::user::register)) - .route("/login", post(handlers::user::login)) - .fallback(teapot.into_service()) - .layer( - ServiceBuilder::new() - .layer(TraceLayer::new_for_http()) - .layer(Extension(postgres)) - .layer(Extension(settings)), - ) + .route("/login", post(handlers::user::login)); + + let path = settings.path.as_str(); + if path.is_empty() { + routes + } else { + Router::new().nest(path, routes) + } + .fallback(teapot.into_service()) + .layer( + ServiceBuilder::new() + .layer(TraceLayer::new_for_http()) + .layer(Extension(postgres)) + .layer(Extension(settings)), + ) } |
