mirror of
https://github.com/NLnetLabs/krill.git
synced 2026-09-22 17:34:56 +02:00
Removed the need for a dev mode and some static imports
This commit is contained in:
committed by
Tim Bruijnzeels
parent
b0dabd63af
commit
ea10c02f63
@@ -6,8 +6,8 @@
|
||||
use std::io;
|
||||
use std::fs::File;
|
||||
use std::sync::{Arc, RwLock, RwLockReadGuard};
|
||||
use actix_web::{pred, fs, server};
|
||||
use actix_web::{App, FromRequest, HttpResponse};
|
||||
use actix_web::{pred, server};
|
||||
use actix_web::{App, FromRequest, HttpResponse };
|
||||
use actix_web::dev::MessageBody;
|
||||
use actix_web::middleware;
|
||||
use actix_web::middleware::identity::CookieIdentityPolicy;
|
||||
@@ -30,10 +30,9 @@ use crate::krilld::krillserver::KrillServer;
|
||||
use crate::remote::rfc8183;
|
||||
use crate::remote::sigmsg::SignedMessage;
|
||||
|
||||
const NOT_FOUND: &[u8] = include_bytes!("../../../ui/dev/html/404.html");
|
||||
const NOT_FOUND: &[u8] = include_bytes!("../../../ui/public/404.html");
|
||||
const LOGIN: &[u8] = include_bytes!("../../../ui/dev/html/login.html");
|
||||
|
||||
|
||||
//------------ PubServerApp --------------------------------------------------
|
||||
|
||||
pub struct PubServerApp(App<Arc<RwLock<KrillServer<DiskKeyStore>>>>);
|
||||
@@ -43,7 +42,7 @@ pub struct PubServerApp(App<Arc<RwLock<KrillServer<DiskKeyStore>>>>);
|
||||
///
|
||||
impl PubServerApp {
|
||||
pub fn new(server: Arc<RwLock<KrillServer<DiskKeyStore>>>) -> Self {
|
||||
let mut app = App::with_state(server)
|
||||
let app = App::with_state(server)
|
||||
.middleware(middleware::Logger::default())
|
||||
.middleware(IdentityService::new(
|
||||
CookieIdentityPolicy::new(&[0; 32])
|
||||
@@ -96,17 +95,7 @@ impl PubServerApp {
|
||||
|_req| HttpResponse::MethodNotAllowed());
|
||||
});
|
||||
|
||||
use std::env;
|
||||
if env::var("KRILL_DEV_MODE").is_ok() {
|
||||
app = app.handler(
|
||||
"/ui/dev",
|
||||
fs::StaticFiles::new("./ui/dev")
|
||||
.unwrap()
|
||||
.show_files_listing()
|
||||
);
|
||||
}
|
||||
|
||||
PubServerApp(with_statics(app))
|
||||
PubServerApp(app)
|
||||
}
|
||||
|
||||
pub fn create_server(
|
||||
@@ -366,17 +355,6 @@ impl server::IntoHttpHandler for PubServerApp {
|
||||
}
|
||||
}
|
||||
|
||||
//------------ Definition of Statics -----------------------------------------
|
||||
|
||||
static CSS: &[u8] = b"text/css";
|
||||
static PNG: &[u8] = b"image/png";
|
||||
|
||||
fn with_statics<S: 'static>(app: App<S>) -> App<S> {
|
||||
statics!(app,
|
||||
"css/custom.css" => CSS => "39e0abcc41c3653600f6d8eadb57b17246f1aca7",
|
||||
"images/404.png" => PNG => "d48f938ae7a05a033d38f55cfa12a08fb3f3f8db",
|
||||
)
|
||||
}
|
||||
|
||||
//------------ HttpRequest ---------------------------------------------------
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ use actix_web::http::StatusCode;
|
||||
/// 'const fn' are stable. So, be sure to use a value here that is unique
|
||||
/// to this resource, and this version of this resource. E.g. calculate its
|
||||
/// hash on the command line and use that in a &str.
|
||||
#[allow(unused_macros)]
|
||||
macro_rules! statics {
|
||||
( $app:expr, $( $path:expr => $mime:expr => $etag:expr, )* ) => {{
|
||||
$app
|
||||
|
||||
Reference in New Issue
Block a user