Skip to content

Commit

Permalink
multi step routing
Browse files Browse the repository at this point in the history
  • Loading branch information
amitu committed Dec 19, 2024
1 parent fd98726 commit a7c5e4f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
1 change: 1 addition & 0 deletions v0.5/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 21 additions & 2 deletions v0.5/fastn-router/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,27 @@ pub enum Route {
NotFound,
// String contains the path, the data may contain more than that was passed to route, e.g., it
// can extract some extra path-specific data from FASTN.ftd file
Document(String, serde_json::Value),
Wasm(String, serde_json::Value),
Document(Document),
Wasm(String),
Redirect(String),
Static(String),
}

pub struct Document {
// this is private yet
#[expect(unused)]
pub(crate) path: String,
#[expect(unused)]
pub(crate) partial: serde_json::Value,
#[expect(unused)]
pub(crate) keys: Vec<String>,
}

#[derive(Debug)]
pub enum RouterError {}

impl Document {
pub fn with_data(self, _data: &[u8]) -> Result<(String, serde_json::Value), RouterError> {
todo!()
}
}
13 changes: 6 additions & 7 deletions v0.5/fastn-router/src/route.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
impl fastn_router::Router {
pub fn route(
&self,
_path: &str,
_method: fastn_router::Method,
_data: &[u8],
) -> fastn_router::Route {
fastn_router::Route::Document("index.ftd".to_string(), serde_json::Value::Null)
pub fn route(&self, _path: &str, _method: fastn_router::Method) -> fastn_router::Route {
fastn_router::Route::Document(fastn_router::Document {
path: "index.ftd".to_string(),
keys: vec![],
partial: serde_json::Value::Null,
})
}
}
2 changes: 1 addition & 1 deletion v0.5/fastn-unresolved/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub enum SoMBase<S, M> {
pub struct Document {
pub aliases: Option<AliasesID>,
pub module: fastn_unresolved::Module,
pub package: fastn_unresolved::Package, // auto import, dependencies
// pub package: fastn_unresolved::Package, // auto import, dependencies
pub module_doc: Option<fastn_section::Span>,
pub definitions: Vec<URD>,
pub content: Vec<URCI>,
Expand Down
5 changes: 3 additions & 2 deletions v0.5/fastn/src/commands/render.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
impl fastn::commands::Render {
pub async fn run(self, _package: &mut fastn_package::Package, router: fastn_router::Router) {
let route = router.route("/", fastn_router::Method::Get, &[]);
let route = router.route("/", fastn_router::Method::Get);
match route {
fastn_router::Route::Document(path, data) => {
fastn_router::Route::Document(doc) => {
let (path, data) = doc.with_data(&[]).unwrap();
let html =
fastn::commands::render::render_document(path.as_str(), data, self.strict)
.await;
Expand Down

0 comments on commit a7c5e4f

Please sign in to comment.