Remove session and errors middleware from static route

Co-Authored-By: Antonio Scandurra <me@as-cii.com>
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld 2021-09-29 10:15:19 -07:00
parent 51a617dd5d
commit 6e8d35379c
2 changed files with 11 additions and 8 deletions

View file

@ -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))?;

View file

@ -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?;