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

Organize which routes are prefixed with "/api" #818

Merged
merged 8 commits into from
Oct 27, 2024
2 changes: 1 addition & 1 deletion src/gen/templates/controller/api/controller.t
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub async fn {{action}}(State(_ctx): State<AppContext>) -> Result<Response> {

pub fn routes() -> Routes {
Routes::new()
.prefix("{{file_name | plural}}/")
.prefix("api/{{file_name | plural}}/")
.add("/", get(index))
{%- for action in actions %}
.add("{{action}}", get({{action}}))
Expand Down
2 changes: 1 addition & 1 deletion src/gen/templates/scaffold/api/controller.t
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub async fn get_one(Path(id): Path<i32>, State(ctx): State<AppContext>) -> Resu

pub fn routes() -> Routes {
Routes::new()
.prefix("{{file_name | plural}}/")
.prefix("api/{{file_name | plural}}/")
.add("/", get(list))
.add("/", post(add))
.add(":id", get(get_one))
Expand Down
4 changes: 1 addition & 3 deletions starters/lightweight-service/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ impl Hooks for App {
}

fn routes(_ctx: &AppContext) -> AppRoutes {
AppRoutes::empty()
.prefix("/api")
.add_route(controllers::home::routes())
AppRoutes::empty().add_route(controllers::home::routes())
}

async fn connect_workers(_ctx: &AppContext, _queue: &Queue) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion starters/lightweight-service/src/controllers/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ async fn current() -> Result<Response> {
}

pub fn routes() -> Routes {
Routes::new().add("/", get(current))
Routes::new().prefix("/api").add("/", get(current))
}
1 change: 0 additions & 1 deletion starters/rest-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ impl Hooks for App {

fn routes(_ctx: &AppContext) -> AppRoutes {
AppRoutes::with_default_routes()
.prefix("/api")
.add_route(controllers::notes::routes())
.add_route(controllers::auth::routes())
.add_route(controllers::user::routes())
Expand Down
2 changes: 1 addition & 1 deletion starters/rest-api/src/controllers/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ async fn login(State(ctx): State<AppContext>, Json(params): Json<LoginParams>) -

pub fn routes() -> Routes {
Routes::new()
.prefix("auth")
.prefix("api/auth")
.add("/register", post(register))
.add("/verify", post(verify))
.add("/login", post(login))
Expand Down
2 changes: 1 addition & 1 deletion starters/rest-api/src/controllers/notes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub async fn get_one(Path(id): Path<i32>, State(ctx): State<AppContext>) -> Resu

pub fn routes() -> Routes {
Routes::new()
.prefix("notes")
.prefix("api/notes")
.add("/", get(list))
.add("/", post(add))
.add("/:id", get(get_one))
Expand Down
4 changes: 3 additions & 1 deletion starters/rest-api/src/controllers/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ async fn current(auth: auth::JWT, State(ctx): State<AppContext>) -> Result<Respo
}

pub fn routes() -> Routes {
Routes::new().prefix("user").add("/current", get(current))
Routes::new()
.prefix("api/user")
.add("/current", get(current))
}
Loading