Remove session and errors middleware from static route
Max Brunsfeld
,
Antonio Scandurra
, and
Nathan Sobo
created
Co-Authored-By: Antonio Scandurra <me@as-cii.com>
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
Change summary
server/src/assets.rs | 8 +++-----
server/src/main.rs | 11 ++++++++---
2 files changed, 11 insertions(+), 8 deletions(-)
Detailed changes
@@ -1,18 +1,16 @@
-use crate::{AppState, Request};
use anyhow::anyhow;
use rust_embed::RustEmbed;
-use std::sync::Arc;
use tide::{http::mime, Server};
#[derive(RustEmbed)]
#[folder = "static"]
struct Static;
-pub fn add_routes(app: &mut Server<Arc<AppState>>) {
- app.at("/static/*path").get(get_static_asset);
+pub fn add_routes(app: &mut Server<()>) {
+ app.at("/*path").get(get_static_asset);
}
-async fn get_static_asset(request: Request) -> tide::Result {
+async fn get_static_asset(request: tide::Request<()>) -> tide::Result {
let path = request.param("path").unwrap();
let content = Static::get(path).ok_or_else(|| anyhow!("asset not found at {}", path))?;
@@ -1,16 +1,16 @@
mod admin;
mod assets;
mod auth;
+mod community;
mod db;
mod env;
mod errors;
mod expiring;
mod github;
mod home;
+mod releases;
mod rpc;
mod team;
-mod releases;
-mod community;
use self::errors::TideResultExt as _;
use anyhow::Result;
@@ -179,11 +179,16 @@ pub async fn run_server(
community::add_routes(&mut web);
admin::add_routes(&mut web);
auth::add_routes(&mut web);
- assets::add_routes(&mut web);
+
+ let mut assets = tide::new();
+ assets.with(CompressMiddleware::new());
+ assets::add_routes(&mut assets);
let mut app = tide::with_state(state.clone());
rpc::add_routes(&mut app, &rpc);
+
app.at("/").nest(web);
+ app.at("/static").nest(assets);
app.listen(listener).await?;