# Routinator UI This crate builds all the assets for the routinator web UI by storing them in a Vec of bytearrays that can be served by Hyper or another web serving crate. The library has two public functions: `get_endpoints()`, returning the Vec and `ui_resource(PATH)` that will return the UI resource. ## Usage Example ```rust use hyper::{Body, Request, Response}; const BASE_URL: &str = "/ui"; const CATCH_ALL_URL: &str = "index.html"; pub fn process_request(req: Request) -> Response { let path = std::path::Path::new(req.uri().path()); if let Ok(p) = path.strip_prefix(BASE_URL) { match routinator_ui::endpoints::ui_resource(p) { Some(endpoint) => serve(endpoint.content, endpoint.content_type), None => { // In order to have the frontend handle all routing and queryparams under BASE_URL, // all unknown URLs that start with /ui will route to the catch_all url defined here. // // Note that we could be smarter about this and do a (somewhat convoluted) regex on // the requested URL to figure out if it makes sense as a search prefix url. if let Some(default) = routinator_ui::endpoints::ui_resource(std::path::Path::new(CATCH_ALL_URL)) { serve(default.content, default.content_type) } else { super::not_found() } } } } else { // The requested URL did *not* start with BASE_URL, so we're returning 404. super::not_found() } } fn serve(data: &'static [u8], ctype: &'static [u8]) -> Response { Response::builder() .header("Content-Type", ctype) .body(data.into()) .unwrap() } ``` ## Building this Library Please do not use `cargo publish` directly on this crate, or bump the version of this create in `Cargo.toml` manually! All versioning (and code generation) is done automatically for this crate by its parent repository, the Vue App. If you need to bump the version of this crate, `git checkout` its parent at [github](https://github.com/NLnetLabs/routinator-ui) and issue: `npm version [major|minor|patch] -m ` Where you can specify `patch`, `minor` or `major` to bump the, well, patch, minor or major version respectively. This will take care of the git (release) branches, the git tags, the version in Cargo.toml in this crate and the version in package.json of its parent. A new release, whether it is patch, minor or major will be deployed to `routinator.nlnetlabs.nl` automatically by the github Actions CI. ## Using it locally You can always refer to a local crate with the well-known mechanisms (including a `{ path = ".." }` argument in the `Cargo.toml` line for this crate in routinator. If you make changes in the parent repo (the Vue App) and compile routinator, you should see the local changes. Also, a .tar.gz file is created for every push to the `main` branch by github Actions and can be downloaded from there.