@@ -60,69 +60,67 @@ export async function preview(vite, vite_config, svelte_config) {
60
60
61
61
// prerendered pages (we can't just use sirv because we need to
62
62
// preserve the correct trailingSlash behaviour)
63
- vite . middlewares . use (
64
- ( req , res , next ) => {
65
- let if_none_match_value = req . headers [ 'if-none-match' ] ;
63
+ vite . middlewares . use ( ( req , res , next ) => {
64
+ let if_none_match_value = req . headers [ 'if-none-match' ] ;
66
65
67
- if ( if_none_match_value ?. startsWith ( 'W/"' ) ) {
68
- if_none_match_value = if_none_match_value . substring ( 2 ) ;
69
- }
66
+ if ( if_none_match_value ?. startsWith ( 'W/"' ) ) {
67
+ if_none_match_value = if_none_match_value . substring ( 2 ) ;
68
+ }
70
69
71
- if ( if_none_match_value === etag ) {
72
- res . statusCode = 304 ;
73
- res . end ( ) ;
74
- return ;
75
- }
70
+ if ( if_none_match_value === etag ) {
71
+ res . statusCode = 304 ;
72
+ res . end ( ) ;
73
+ return ;
74
+ }
76
75
77
- const { pathname, search } = new URL ( /** @type {string } */ ( req . url ) , 'http://dummy' ) ;
78
-
79
- let filename = normalizePath (
80
- join ( svelte_config . kit . outDir , 'output/prerendered/pages' + pathname )
81
- ) ;
82
- let prerendered = is_file ( filename ) ;
83
-
84
- if ( ! prerendered ) {
85
- const has_trailing_slash = pathname . endsWith ( '/' ) ;
86
- const html_filename = `${ filename } ${ has_trailing_slash ? 'index.html' : '.html' } ` ;
87
-
88
- /** @type {string | undefined } */
89
- let redirect ;
90
-
91
- if ( is_file ( html_filename ) ) {
92
- filename = html_filename ;
93
- prerendered = true ;
94
- } else if ( has_trailing_slash ) {
95
- if ( is_file ( filename . slice ( 0 , - 1 ) + '.html' ) ) {
96
- redirect = pathname . slice ( 0 , - 1 ) ;
97
- }
98
- } else if ( is_file ( filename + '/index.html' ) ) {
99
- redirect = pathname + '/' ;
100
- }
76
+ const { pathname, search } = new URL ( /** @type {string } */ ( req . url ) , 'http://dummy' ) ;
77
+
78
+ let filename = normalizePath (
79
+ join ( svelte_config . kit . outDir , 'output/prerendered/pages' + pathname )
80
+ ) ;
81
+ let prerendered = is_file ( filename ) ;
101
82
102
- if ( redirect ) {
103
- if ( search ) redirect += search ;
104
- res . writeHead ( 307 , {
105
- location : redirect
106
- } ) ;
83
+ if ( ! prerendered ) {
84
+ const has_trailing_slash = pathname . endsWith ( '/' ) ;
85
+ const html_filename = `${ filename } ${ has_trailing_slash ? 'index.html' : '.html' } ` ;
107
86
108
- res . end ( ) ;
87
+ /** @type {string | undefined } */
88
+ let redirect ;
109
89
110
- return ;
90
+ if ( is_file ( html_filename ) ) {
91
+ filename = html_filename ;
92
+ prerendered = true ;
93
+ } else if ( has_trailing_slash ) {
94
+ if ( is_file ( filename . slice ( 0 , - 1 ) + '.html' ) ) {
95
+ redirect = pathname . slice ( 0 , - 1 ) ;
111
96
}
97
+ } else if ( is_file ( filename + '/index.html' ) ) {
98
+ redirect = pathname + '/' ;
112
99
}
113
100
114
- if ( prerendered ) {
115
- res . writeHead ( 200 , {
116
- 'content-type' : lookup ( pathname ) || 'text/html' ,
117
- etag
101
+ if ( redirect ) {
102
+ if ( search ) redirect += search ;
103
+ res . writeHead ( 307 , {
104
+ location : redirect
118
105
} ) ;
119
106
120
- fs . createReadStream ( filename ) . pipe ( res ) ;
121
- } else {
122
- next ( ) ;
107
+ res . end ( ) ;
108
+
109
+ return ;
123
110
}
124
111
}
125
- ) ;
112
+
113
+ if ( prerendered ) {
114
+ res . writeHead ( 200 , {
115
+ 'content-type' : lookup ( pathname ) || 'text/html' ,
116
+ etag
117
+ } ) ;
118
+
119
+ fs . createReadStream ( filename ) . pipe ( res ) ;
120
+ } else {
121
+ next ( ) ;
122
+ }
123
+ } ) ;
126
124
127
125
// SSR
128
126
vite . middlewares . use ( async ( req , res ) => {
0 commit comments