-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for (sub)domain routing
- Loading branch information
1 parent
8989aa2
commit b3426a2
Showing
395 changed files
with
10,679 additions
and
6,295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
doc_examples/guide/routing/domain_guards/project-catch_all.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
```rust title="src/catch_all/blueprint.rs" hl_lines="7" | ||
use pavex::blueprint::router::GET; | ||
use pavex::blueprint::Blueprint; | ||
use pavex::f; | ||
pub fn bp() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.domain("{*any}.pavex.dev").nest(sub_bp()); | ||
bp | ||
} | ||
fn sub_bp() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.route(GET, "/", f!(super::handler)); | ||
// Other routes... | ||
bp | ||
} | ||
``` |
18 changes: 18 additions & 0 deletions
18
doc_examples/guide/routing/domain_guards/project-dynamic.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
```rust title="src/dynamic/blueprint.rs" hl_lines="7" | ||
use pavex::blueprint::router::GET; | ||
use pavex::blueprint::Blueprint; | ||
use pavex::f; | ||
pub fn bp() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.domain("{sub}.pavex.dev").nest(sub_bp()); | ||
bp | ||
} | ||
fn sub_bp() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.route(GET, "/", f!(super::index)); | ||
// Other routes... | ||
bp | ||
} | ||
``` |
13 changes: 13 additions & 0 deletions
13
doc_examples/guide/routing/domain_guards/project-fallback.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
```rust title="src/fallback/blueprint.rs" hl_lines="9" | ||
use pavex::blueprint::Blueprint; | ||
use pavex::f; | ||
pub fn bp() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.domain("pavex.dev").nest(website_bp()); | ||
bp.domain("api.pavex.dev").prefix("/v1").nest(api_bp()); | ||
// If no domain matches, serve a 404 page. | ||
bp.fallback(f!(super::unknown_domain)); | ||
bp | ||
} | ||
``` |
28 changes: 28 additions & 0 deletions
28
doc_examples/guide/routing/domain_guards/project-intro.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
```rust title="src/intro/blueprint.rs" hl_lines="8 10" | ||
use pavex::blueprint::router::GET; | ||
use pavex::blueprint::Blueprint; | ||
use pavex::f; | ||
pub fn bp() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
// Serve the website from the root domain... | ||
bp.domain("pavex.dev").nest(website_bp()); | ||
// ...while reserving a subdomain for the REST API. | ||
bp.domain("api.pavex.dev").prefix("/v1").nest(api_bp()); | ||
bp | ||
} | ||
fn website_bp() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.route(GET, "/", f!(super::index)); | ||
// Other web pages... | ||
bp | ||
} | ||
fn api_bp() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.route(GET, "/users", f!(super::users)); | ||
// Other API routes... | ||
bp | ||
} | ||
``` |
18 changes: 18 additions & 0 deletions
18
doc_examples/guide/routing/domain_guards/project-multi.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
```rust title="src/multi/blueprint.rs" hl_lines="7" | ||
use pavex::blueprint::router::GET; | ||
use pavex::blueprint::Blueprint; | ||
use pavex::f; | ||
pub fn bp() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.domain("{user_id}.{tenant_id}.pavex.dev").nest(user_bp()); | ||
bp | ||
} | ||
fn user_bp() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.route(GET, "/", f!(super::index)); | ||
// Other routes... | ||
bp | ||
} | ||
``` |
18 changes: 18 additions & 0 deletions
18
doc_examples/guide/routing/domain_guards/project-static.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
```rust title="src/static_/blueprint.rs" hl_lines="7" | ||
use pavex::blueprint::router::GET; | ||
use pavex::blueprint::Blueprint; | ||
use pavex::f; | ||
pub fn bp() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.domain("pavex.dev").nest(pavex_bp()); | ||
bp | ||
} | ||
fn pavex_bp() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.route(GET, "/", f!(super::index)); | ||
// Other routes... | ||
bp | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/target | ||
Cargo.lock |
13 changes: 13 additions & 0 deletions
13
doc_examples/guide/routing/domain_guards/project/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "domain_guards" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
pavex = { path = "../../../../../libs/pavex" } | ||
pavex_cli_client = { path = "../../../../../libs/pavex_cli_client" } | ||
serde = { version = "1", features = ["derive"] } | ||
cargo_px_env = "0.1" | ||
|
||
[workspace] | ||
members = [".", "server_sdk"] |
8 changes: 8 additions & 0 deletions
8
doc_examples/guide/routing/domain_guards/project/server_sdk/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "domain_guards_server_sdk" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[package.metadata.px.generate] | ||
generator_type = "cargo_workspace_binary" | ||
generator_name = "domain_guards" |
1 change: 1 addition & 0 deletions
1
doc_examples/guide/routing/domain_guards/project/server_sdk/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
12 changes: 12 additions & 0 deletions
12
doc_examples/guide/routing/domain_guards/project/src/blueprint.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use pavex::blueprint::Blueprint; | ||
|
||
pub fn blueprint() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.nest(crate::intro::bp()); | ||
bp.prefix("/static").nest(crate::static_::bp()); | ||
bp.prefix("/dynamic").nest(crate::dynamic::bp()); | ||
bp.prefix("/multi").nest(crate::multi::bp()); | ||
bp.prefix("/catch_all").nest(crate::catch_all::bp()); | ||
bp.prefix("/fallback").nest(crate::fallback::bp()); | ||
bp | ||
} |
16 changes: 16 additions & 0 deletions
16
doc_examples/guide/routing/domain_guards/project/src/catch_all/blueprint.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use pavex::blueprint::router::GET; | ||
use pavex::blueprint::Blueprint; | ||
use pavex::f; | ||
|
||
pub fn bp() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.domain("{*any}.pavex.dev").nest(sub_bp()); | ||
bp | ||
} | ||
|
||
fn sub_bp() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.route(GET, "/", f!(super::handler)); | ||
// Other routes... | ||
bp | ||
} |
5 changes: 5 additions & 0 deletions
5
doc_examples/guide/routing/domain_guards/project/src/catch_all/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub use blueprint::bp; | ||
pub use routes::*; | ||
|
||
mod blueprint; | ||
mod routes; |
5 changes: 5 additions & 0 deletions
5
doc_examples/guide/routing/domain_guards/project/src/catch_all/routes.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use pavex::http::StatusCode; | ||
|
||
pub fn handler() -> StatusCode { | ||
StatusCode::OK | ||
} |
16 changes: 16 additions & 0 deletions
16
doc_examples/guide/routing/domain_guards/project/src/dynamic/blueprint.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use pavex::blueprint::router::GET; | ||
use pavex::blueprint::Blueprint; | ||
use pavex::f; | ||
|
||
pub fn bp() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.domain("{sub}.pavex.dev").nest(sub_bp()); | ||
bp | ||
} | ||
|
||
fn sub_bp() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.route(GET, "/", f!(super::index)); | ||
// Other routes... | ||
bp | ||
} |
5 changes: 5 additions & 0 deletions
5
doc_examples/guide/routing/domain_guards/project/src/dynamic/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub use blueprint::bp; | ||
pub use routes::*; | ||
|
||
mod blueprint; | ||
mod routes; |
5 changes: 5 additions & 0 deletions
5
doc_examples/guide/routing/domain_guards/project/src/dynamic/routes.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use pavex::http::StatusCode; | ||
|
||
pub fn index() -> StatusCode { | ||
StatusCode::OK | ||
} |
25 changes: 25 additions & 0 deletions
25
doc_examples/guide/routing/domain_guards/project/src/fallback/blueprint.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use pavex::blueprint::Blueprint; | ||
use pavex::f; | ||
|
||
pub fn bp() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.domain("pavex.dev").nest(website_bp()); | ||
bp.domain("api.pavex.dev").prefix("/v1").nest(api_bp()); | ||
// If no domain matches, serve a 404 page. | ||
bp.fallback(f!(super::unknown_domain)); | ||
bp | ||
} | ||
|
||
fn website_bp() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.route(pavex::blueprint::router::GET, "/", f!(super::index)); | ||
// Other web pages... | ||
bp | ||
} | ||
|
||
fn api_bp() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.route(pavex::blueprint::router::GET, "/users", f!(super::users)); | ||
// Other API routes... | ||
bp | ||
} |
5 changes: 5 additions & 0 deletions
5
doc_examples/guide/routing/domain_guards/project/src/fallback/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub use blueprint::bp; | ||
pub use routes::*; | ||
|
||
mod blueprint; | ||
mod routes; |
13 changes: 13 additions & 0 deletions
13
doc_examples/guide/routing/domain_guards/project/src/fallback/routes.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use pavex::http::StatusCode; | ||
|
||
pub fn index() -> StatusCode { | ||
StatusCode::OK | ||
} | ||
|
||
pub fn unknown_domain() -> StatusCode { | ||
StatusCode::NOT_FOUND | ||
} | ||
|
||
pub fn users() -> StatusCode { | ||
StatusCode::OK | ||
} |
26 changes: 26 additions & 0 deletions
26
doc_examples/guide/routing/domain_guards/project/src/intro/blueprint.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use pavex::blueprint::router::GET; | ||
use pavex::blueprint::Blueprint; | ||
use pavex::f; | ||
|
||
pub fn bp() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
// Serve the website from the root domain... | ||
bp.domain("pavex.dev").nest(website_bp()); | ||
// ...while reserving a subdomain for the REST API. | ||
bp.domain("api.pavex.dev").prefix("/v1").nest(api_bp()); | ||
bp | ||
} | ||
|
||
fn website_bp() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.route(GET, "/", f!(super::index)); | ||
// Other web pages... | ||
bp | ||
} | ||
|
||
fn api_bp() -> Blueprint { | ||
let mut bp = Blueprint::new(); | ||
bp.route(GET, "/users", f!(super::users)); | ||
// Other API routes... | ||
bp | ||
} |
Oops, something went wrong.