mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-12-23 13:10:06 +01:00
improve mini dashboard routing
This commit is contained in:
parent
7ec752ed1c
commit
b1a5ef0aab
@ -15,16 +15,17 @@ pub use option::Opt;
|
|||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! create_app {
|
macro_rules! create_app {
|
||||||
($data:expr, $enable_frontend:expr) => {{
|
($data:expr, $enable_frontend:expr) => {
|
||||||
|
{
|
||||||
use actix_cors::Cors;
|
use actix_cors::Cors;
|
||||||
use actix_web::middleware::TrailingSlash;
|
use actix_web::middleware::TrailingSlash;
|
||||||
use actix_web::App;
|
use actix_web::{App, HttpResponse};
|
||||||
use actix_web::{middleware, web};
|
use actix_web::{middleware, web};
|
||||||
use meilisearch_http::error::payload_error_handler;
|
use meilisearch_http::error::payload_error_handler;
|
||||||
use meilisearch_http::routes::*;
|
use meilisearch_http::routes::*;
|
||||||
|
|
||||||
#[cfg(feature = "mini-dashboard")]
|
#[cfg(feature = "mini-dashboard")]
|
||||||
use actix_web_static_files::ResourceFiles;
|
use actix_web_static_files::Resource;
|
||||||
|
|
||||||
#[cfg(feature = "mini-dashboard")]
|
#[cfg(feature = "mini-dashboard")]
|
||||||
mod dashboard {
|
mod dashboard {
|
||||||
@ -53,9 +54,24 @@ macro_rules! create_app {
|
|||||||
.configure(dump::services);
|
.configure(dump::services);
|
||||||
#[cfg(feature = "mini-dashboard")]
|
#[cfg(feature = "mini-dashboard")]
|
||||||
let app = if $enable_frontend {
|
let app = if $enable_frontend {
|
||||||
|
let mut app = app;
|
||||||
let generated = dashboard::generate();
|
let generated = dashboard::generate();
|
||||||
let service = ResourceFiles::new("/", generated);
|
let mut scope = web::scope("/");
|
||||||
app.service(service)
|
// Generate routes for mini-dashboard assets
|
||||||
|
for (path, resource) in generated.into_iter() {
|
||||||
|
let Resource {mime_type, data, ..} = resource;
|
||||||
|
// Redirect index.html to /
|
||||||
|
if path == "index.html" {
|
||||||
|
app = app.service(web::resource("/").route(web::get().to(move || {
|
||||||
|
HttpResponse::Ok().content_type(mime_type).body(data)
|
||||||
|
})));
|
||||||
|
} else {
|
||||||
|
scope = scope.service(web::resource(path).route(web::get().to(move || {
|
||||||
|
HttpResponse::Ok().content_type(mime_type).body(data)
|
||||||
|
})));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
app.service(scope)
|
||||||
} else {
|
} else {
|
||||||
app.service(running)
|
app.service(running)
|
||||||
};
|
};
|
||||||
@ -74,5 +90,8 @@ macro_rules! create_app {
|
|||||||
.wrap(middleware::Logger::default())
|
.wrap(middleware::Logger::default())
|
||||||
.wrap(middleware::Compress::default())
|
.wrap(middleware::Compress::default())
|
||||||
.wrap(middleware::NormalizePath::new(TrailingSlash::Trim))
|
.wrap(middleware::NormalizePath::new(TrailingSlash::Trim))
|
||||||
}};
|
.default_service(
|
||||||
|
web::route().to(|| HttpResponse::NotFound()))
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user