v0.8.15
This commit is contained in:
+36
-8
@@ -29,7 +29,8 @@ use crate::{
|
||||
};
|
||||
|
||||
const INDEX_HTML: &str = include_str!("../web/index.html");
|
||||
const APP_JS: &str = include_str!("../web/app.js");
|
||||
const NOT_FOUND_HTML: &str = include_str!("../web/404.html");
|
||||
const APP_JS: &str = include_str!(concat!(env!("OUT_DIR"), "/app.bundle.js"));
|
||||
const THEME_INIT_JS: &str = include_str!("../web/theme-init.js");
|
||||
const STYLES_CSS: &str = include_str!("../web/styles.css");
|
||||
const MANIFEST: &str = include_str!("../web/manifest.webmanifest");
|
||||
@@ -37,6 +38,26 @@ const SERVICE_WORKER: &str = include_str!("../web/sw.js");
|
||||
const FAVICON: &str = include_str!("../web/favicon.svg");
|
||||
include!(concat!(env!("OUT_DIR"), "/languages.rs"));
|
||||
|
||||
const SPA_ROUTES: &[&str] = &[
|
||||
"/dashboard",
|
||||
"/devices",
|
||||
"/zones",
|
||||
"/groups",
|
||||
"/schedules",
|
||||
"/automations",
|
||||
"/simulation",
|
||||
"/night-mode",
|
||||
"/home-assistant",
|
||||
"/settings",
|
||||
"/events",
|
||||
"/history",
|
||||
"/history/overview",
|
||||
"/history/zones",
|
||||
"/history/devices",
|
||||
"/history/sensors",
|
||||
"/history/custom",
|
||||
];
|
||||
|
||||
pub fn router(state: AppState) -> Router {
|
||||
let protected = Router::new()
|
||||
.route("/api/bootstrap", get(bootstrap))
|
||||
@@ -88,23 +109,29 @@ pub fn router(state: AppState) -> Router {
|
||||
.route("/api/integrations/home-assistant/zones/:id/control", post(update_home_assistant_zone_control))
|
||||
.route_layer(middleware::from_fn_with_state(state.clone(), home_assistant_auth));
|
||||
|
||||
let app = Router::new()
|
||||
let mut app = Router::new()
|
||||
.route("/api/health", get(health))
|
||||
.route("/ws", get(websocket))
|
||||
.route("/", get(index))
|
||||
.route("/index.html", get(index))
|
||||
.route("/app.js", get(app_js))
|
||||
.route("/theme-init.js", get(theme_init_js))
|
||||
.route("/styles.css", get(styles_css))
|
||||
.route(APP_JS_ASSET_PATH, get(app_js))
|
||||
.route(THEME_INIT_ASSET_PATH, get(theme_init_js))
|
||||
.route(STYLES_CSS_ASSET_PATH, get(styles_css))
|
||||
.route("/app.js", get(app_js_legacy))
|
||||
.route("/theme-init.js", get(theme_init_js_legacy))
|
||||
.route("/styles.css", get(styles_css_legacy))
|
||||
.route("/manifest.webmanifest", get(manifest))
|
||||
.route("/sw.js", get(service_worker))
|
||||
.route("/favicon.svg", get(favicon))
|
||||
.route("/lang/index.json", get(language_index))
|
||||
.route("/lang/:file", get(language_file))
|
||||
.merge(protected)
|
||||
.merge(home_assistant_api)
|
||||
.fallback(index)
|
||||
;
|
||||
.merge(home_assistant_api);
|
||||
|
||||
for &route in SPA_ROUTES {
|
||||
app = app.route(route, get(index));
|
||||
}
|
||||
let app = app.fallback(not_found);
|
||||
|
||||
let app = if state.config.base_path.is_empty() {
|
||||
app
|
||||
@@ -117,6 +144,7 @@ pub fn router(state: AppState) -> Router {
|
||||
async move { Redirect::permanent(&redirect_to) }
|
||||
}))
|
||||
.nest(&base, app)
|
||||
.fallback(not_found)
|
||||
};
|
||||
|
||||
app
|
||||
|
||||
Reference in New Issue
Block a user