11use std:: net:: SocketAddr ;
22
3- use axum:: headers:: { ContentEncoding , HeaderName } ;
3+ use axum:: headers:: HeaderName ;
44use axum:: http:: { HeaderValue , StatusCode } ;
55use axum:: response:: { Html , IntoResponse , Response } ;
66use axum:: routing:: { get, get_service} ;
7- use axum:: { Router , TypedHeader } ;
7+ use axum:: Router ;
88use tower:: ServiceBuilder ;
9+ use tower_http:: compression:: CompressionLayer ;
910use tower_http:: services:: ServeDir ;
1011use tower_http:: set_header:: SetResponseHeaderLayer ;
1112
@@ -22,9 +23,10 @@ pub struct Options {
2223}
2324
2425pub async fn run_server ( options : Options , output : WasmBindgenOutput ) -> Result < ( ) > {
25- let WasmBindgenOutput { js, compressed_wasm } = output;
26+ let WasmBindgenOutput { js, wasm } = output;
2627
2728 let middleware_stack = ServiceBuilder :: new ( )
29+ . layer ( CompressionLayer :: new ( ) )
2830 . layer ( SetResponseHeaderLayer :: if_not_present (
2931 HeaderName :: from_static ( "cross-origin-opener-policy" ) ,
3032 HeaderValue :: from_static ( "same-origin" ) ,
@@ -41,14 +43,10 @@ pub async fn run_server(options: Options, output: WasmBindgenOutput) -> Result<(
4143
4244 let serve_dir = get_service ( ServeDir :: new ( "." ) ) . handle_error ( internal_server_error) ;
4345
44- let serve_wasm = || async move {
45- ( TypedHeader ( ContentEncoding :: gzip ( ) ) , WithContentType ( "application/wasm" , compressed_wasm) )
46- } ;
47-
4846 let app = Router :: new ( )
4947 . route ( "/" , get ( move || async { Html ( html) } ) )
5048 . route ( "/api/wasm.js" , get ( || async { WithContentType ( "application/javascript" , js) } ) )
51- . route ( "/api/wasm.wasm" , get ( serve_wasm ) )
49+ . route ( "/api/wasm.wasm" , get ( || async { WithContentType ( "application/wasm" , wasm ) } ) )
5250 . route ( "/api/version" , get ( move || async { version } ) )
5351 . fallback ( serve_dir)
5452 . layer ( middleware_stack) ;
0 commit comments