@@ -5,15 +5,15 @@ use actix_web::{
5
5
} ;
6
6
7
7
macro_rules! static_file_endpoint {
8
- ( $filestem: literal, $extension: literal) => { {
8
+ ( $filestem: literal, $extension: literal, $mime : literal ) => { {
9
9
const FILENAME_WITH_TAG : & str = static_filename!( concat!( $filestem, "." , $extension) ) ;
10
10
web:: resource( FILENAME_WITH_TAG ) . to( |req: HttpRequest | async move {
11
11
let file_etag = EntityTag :: new_strong( FILENAME_WITH_TAG . to_string( ) ) ;
12
12
if matches!( IfNoneMatch :: parse( & req) , Ok ( IfNoneMatch :: Items ( etags) ) if etags. iter( ) . any( |etag| etag. weak_eq( & file_etag) ) ) {
13
13
return HttpResponse :: NotModified ( ) . finish( ) ;
14
14
}
15
15
HttpResponse :: Ok ( )
16
- . content_type( concat!( "text/" , $extension , ";charset=UTF-8" ) )
16
+ . content_type( concat!( $mime , ";charset=UTF-8" ) )
17
17
. insert_header( CacheControl ( vec![
18
18
CacheDirective :: Public ,
19
19
CacheDirective :: MaxAge ( 3600 * 24 * 7 ) ,
@@ -28,9 +28,9 @@ macro_rules! static_file_endpoint {
28
28
}
29
29
30
30
pub fn js ( ) -> Resource {
31
- static_file_endpoint ! ( "sqlpage" , "js" )
31
+ static_file_endpoint ! ( "sqlpage" , "js" , "application/javascript" )
32
32
}
33
33
34
34
pub fn css ( ) -> Resource {
35
- static_file_endpoint ! ( "sqlpage" , "css" )
35
+ static_file_endpoint ! ( "sqlpage" , "css" , "text/css" )
36
36
}
0 commit comments