11use std:: net:: SocketAddr ;
22
33use axum:: http:: { HeaderValue , StatusCode } ;
4- use axum:: response:: { Html , IntoResponse , Response } ;
4+ use axum:: response:: { Headers , Html , IntoResponse , Response } ;
55use axum:: routing:: { get, get_service} ;
66use axum:: Router ;
77use tower:: ServiceBuilder ;
@@ -19,7 +19,7 @@ pub struct Options {
1919}
2020
2121pub async fn run_server ( options : Options , output : WasmBindgenOutput ) -> Result < ( ) > {
22- let WasmBindgenOutput { js, wasm } = output;
22+ let WasmBindgenOutput { js, compressed_wasm } = output;
2323
2424 let middleware_stack = ServiceBuilder :: new ( ) . into_inner ( ) ;
2525
@@ -29,10 +29,16 @@ pub async fn run_server(options: Options, output: WasmBindgenOutput) -> Result<(
2929
3030 let serve_dir = get_service ( ServeDir :: new ( "." ) ) . handle_error ( internal_server_error) ;
3131
32+ let serve_wasm = || async move {
33+ let headers = Headers ( std:: iter:: once ( ( "Content-Encoding" , "gzip" ) ) ) ;
34+ let response = WithContentType ( "application/wasm" , compressed_wasm) ;
35+ ( headers, response)
36+ } ;
37+
3238 let app = Router :: new ( )
3339 . route ( "/" , get ( move || async { Html ( html) } ) )
3440 . route ( "/api/wasm.js" , get ( || async { WithContentType ( "application/javascript" , js) } ) )
35- . route ( "/api/wasm.wasm" , get ( || async { WithContentType ( "application/wasm" , wasm ) } ) )
41+ . route ( "/api/wasm.wasm" , get ( serve_wasm ) )
3642 . route ( "/api/version" , get ( move || async { version } ) )
3743 . fallback ( serve_dir)
3844 . layer ( middleware_stack) ;
0 commit comments