Add assets route

This commit is contained in:
Pierre HUBERT 2022-03-30 09:40:46 +02:00
parent 6d8b8979ca
commit d75242d213
8 changed files with 12268 additions and 27 deletions

694
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -7,6 +7,8 @@ edition = "2021"
[dependencies]
rocket = "0.5.0-rc.1"
rocket_dyn_templates = { version = "0.1.0-rc.1", features = ["tera"] }
include_dir = "0.7.2"
log = "0.4.16"
serde_json = "1.0.79"
env_logger = "0.9.0"

11562
assets/css/bootstrap.css vendored Normal file

File diff suppressed because it is too large Load Diff

5
assets/css/login.css Normal file
View File

@ -0,0 +1,5 @@
/**
* Login page
*
* @author Pierre Hubert
*/

View File

@ -0,0 +1,22 @@
use std::path::PathBuf;
use include_dir::{Dir, include_dir};
use rocket::http::{ContentType, Status};
/// Assets directory
static ASSETS_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/assets");
#[get("/<file..>")]
pub fn assets_route(file: PathBuf) -> (Status, (ContentType, &'static [u8])) {
match ASSETS_DIR.get_file(file) {
None =>
(Status::NotFound, (ContentType::Text, "404 Not found".as_bytes())),
Some(file) => {
(Status::Ok, (
ContentType::from_extension(file.path().extension().unwrap_or_default()
.to_string_lossy().as_ref())
.unwrap_or(ContentType::Binary),
file.contents()))
}
}
}

1
src/controllers/mod.rs Normal file
View File

@ -0,0 +1 @@
pub mod assets_controller;

View File

@ -1,3 +1,8 @@
#[macro_use]
extern crate rocket;
pub mod data;
pub mod utils;
pub mod constants;
pub mod controllers;

View File

@ -7,6 +7,7 @@ use basic_oidc::constants::{DEFAULT_ADMIN_PASSWORD, DEFAULT_ADMIN_USERNAME};
use basic_oidc::data::app_config::AppConfig;
use basic_oidc::data::entity_manager::EntityManager;
use basic_oidc::data::user::{hash_password, User};
use basic_oidc::controllers::assets_controller::assets_route;
#[get("/health")]
fn index() -> &'static str {
@ -19,6 +20,7 @@ async fn main() -> Result<(), rocket::Error> {
let rocket = rocket::build()
.mount("/", routes![index])
.mount("/assets", routes![assets_route])
.attach(AdHoc::config::<AppConfig>());
let figment = rocket.figment();