11use std:: net:: SocketAddr ;
22
3- use axum:: headers:: ContentEncoding ;
43use axum:: http:: { HeaderValue , StatusCode } ;
54use axum:: response:: { Html , IntoResponse , Response } ;
65use axum:: routing:: { get, get_service} ;
7- use axum:: { Router , TypedHeader } ;
6+ use axum:: Router ;
87use tower:: ServiceBuilder ;
8+ use tower_http:: compression:: CompressionLayer ;
99use tower_http:: services:: ServeDir ;
1010
1111use crate :: wasm_bindgen:: WasmBindgenOutput ;
@@ -21,24 +21,20 @@ pub struct Options {
2121}
2222
2323pub async fn run_server ( options : Options , output : WasmBindgenOutput ) -> Result < ( ) > {
24- let WasmBindgenOutput { js, compressed_wasm } = output;
24+ let WasmBindgenOutput { js, wasm } = output;
2525
26- let middleware_stack = ServiceBuilder :: new ( ) . into_inner ( ) ;
26+ let middleware_stack = ServiceBuilder :: new ( ) . layer ( CompressionLayer :: new ( ) ) . into_inner ( ) ;
2727
2828 let version = generate_version ( ) ;
2929
3030 let html = include_str ! ( "../static/index.html" ) . replace ( "{{ TITLE }}" , & options. title ) ;
3131
3232 let serve_dir = get_service ( ServeDir :: new ( "." ) ) . handle_error ( internal_server_error) ;
3333
34- let serve_wasm = || async move {
35- ( TypedHeader ( ContentEncoding :: gzip ( ) ) , WithContentType ( "application/wasm" , compressed_wasm) )
36- } ;
37-
3834 let app = Router :: new ( )
3935 . route ( "/" , get ( move || async { Html ( html) } ) )
4036 . route ( "/api/wasm.js" , get ( || async { WithContentType ( "application/javascript" , js) } ) )
41- . route ( "/api/wasm.wasm" , get ( serve_wasm ) )
37+ . route ( "/api/wasm.wasm" , get ( || async { WithContentType ( "application/wasm" , wasm ) } ) )
4238 . route ( "/api/version" , get ( move || async { version } ) )
4339 . fallback ( serve_dir)
4440 . layer ( middleware_stack) ;
0 commit comments