Add configuration options
This commit is contained in:
parent
5d28a2e707
commit
270fed54f0
16 changed files with 272 additions and 83 deletions
|
|
@ -1,22 +1,14 @@
|
|||
use axum::{routing::get, Router};
|
||||
|
||||
use crate::{handlers, formats::Format};
|
||||
use crate::{formats::Format, handlers, types::Graph};
|
||||
|
||||
pub fn new() -> Router {
|
||||
Router::new()
|
||||
pub fn new(graph: &Graph) -> Router {
|
||||
let mut router = Router::new()
|
||||
.route(
|
||||
"/",
|
||||
get(|| handlers::navigation::nexus("index.html"))
|
||||
get(|| handlers::navigation::page("index.html"))
|
||||
.post(handlers::navigation::search),
|
||||
)
|
||||
.route(
|
||||
"/graph/toml",
|
||||
get(|| handlers::fixed::serial(&Format::Toml)),
|
||||
)
|
||||
.route(
|
||||
"/graph/json",
|
||||
get(|| handlers::fixed::serial(&Format::Json)),
|
||||
)
|
||||
.route(
|
||||
"/static/style.css",
|
||||
get(|| handlers::fixed::file("./static/style.css", "text/css")),
|
||||
|
|
@ -31,11 +23,32 @@ pub fn new() -> Router {
|
|||
"/node/{node_id}",
|
||||
get(handlers::graph::node).post(handlers::graph::node),
|
||||
)
|
||||
.route("/tree", get(|| handlers::navigation::nexus("tree.html")))
|
||||
.route("/about", get(|| handlers::template::fixed("about.html")))
|
||||
.route(
|
||||
"/acknowledgments",
|
||||
get(|| handlers::template::fixed("acknowledgments.html")),
|
||||
)
|
||||
.fallback(handlers::error::not_found)
|
||||
.fallback(handlers::error::not_found);
|
||||
|
||||
if graph.meta.config.about {
|
||||
router = router
|
||||
.route("/about", get(|| handlers::navigation::page("about.html")));
|
||||
}
|
||||
|
||||
if graph.meta.config.tree {
|
||||
router = router
|
||||
.route("/tree", get(|| handlers::navigation::page("tree.html")));
|
||||
}
|
||||
|
||||
if graph.meta.config.raw {
|
||||
if graph.meta.config.raw_json {
|
||||
router = router.route(
|
||||
"/graph/json",
|
||||
get(|| handlers::fixed::serial(&Format::Json)),
|
||||
);
|
||||
}
|
||||
if graph.meta.config.raw_toml {
|
||||
router = router.route(
|
||||
"/graph/toml",
|
||||
get(|| handlers::fixed::serial(&Format::Toml)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
router
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue