Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for prepending a path to all routes for the server #484

Merged
merged 4 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions atuin-server/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,27 @@ 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))
.route("/sync/calendar/:focus", get(handlers::history::calendar))
.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)),
)
}
2 changes: 2 additions & 0 deletions atuin-server/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub const HISTORY_PAGE_SIZE: i64 = 100;
pub struct Settings {
pub host: String,
pub port: u16,
pub path: String,
pub db_uri: String,
pub open_registration: bool,
pub max_history_length: usize,
Expand All @@ -35,6 +36,7 @@ impl Settings {
.set_default("port", 8888)?
.set_default("open_registration", false)?
.set_default("max_history_length", 8192)?
.set_default("path", "")?
.add_source(
Environment::with_prefix("atuin")
.prefix_separator("_")
Expand Down
6 changes: 6 additions & 0 deletions docs/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ Defaults to `false`.

A valid postgres URI, where the user and history data will be saved to.

### path

A path to prepend to all the routes of the server. Any empty string means that nothing will be prepended.

Defaults to `""`

## Container deployment instructions

You can deploy you own atuin server in a container:
Expand Down