@@ -50,15 +50,15 @@ export async function preview({ port, host, config, https: use_https = false })
50
50
const { Server, override } = await import ( pathToFileURL ( index_file ) . href ) ;
51
51
const { manifest } = await import ( pathToFileURL ( manifest_file ) . href ) ;
52
52
53
- const server = new Server ( manifest ) ;
54
-
55
53
override ( {
56
54
paths : { base, assets } ,
57
55
prerendering : false ,
58
56
protocol : use_https ? 'https' : 'http' ,
59
57
read : ( file ) => fs . readFileSync ( join ( config . kit . files . assets , file ) )
60
58
} ) ;
61
59
60
+ const server = new Server ( manifest ) ;
61
+
62
62
const handle = compose ( [
63
63
// files in `static`
64
64
scoped ( assets , mutable ( config . kit . files . assets ) ) ,
@@ -96,7 +96,7 @@ export async function preview({ port, host, config, https: use_https = false })
96
96
97
97
if ( normalized !== pathname ) {
98
98
res . writeHead ( 307 , {
99
- location : normalized + search
99
+ location : base + normalized + search
100
100
} ) ;
101
101
res . end ( ) ;
102
102
return ;
@@ -124,7 +124,7 @@ export async function preview({ port, host, config, https: use_https = false })
124
124
} ) ,
125
125
126
126
// SSR
127
- scoped ( base , async ( req , res ) => {
127
+ async ( req , res ) => {
128
128
const protocol = use_https ? 'https' : 'http' ;
129
129
const host = req . headers [ 'host' ] ;
130
130
@@ -138,7 +138,7 @@ export async function preview({ port, host, config, https: use_https = false })
138
138
}
139
139
140
140
setResponse ( res , await server . respond ( request ) ) ;
141
- } )
141
+ }
142
142
] ) ;
143
143
144
144
const vite_config = ( config . kit . vite && ( await config . kit . vite ( ) ) ) || { } ;
@@ -219,9 +219,10 @@ function scoped(scope, handler) {
219
219
220
220
return ( req , res , next ) => {
221
221
if ( req . url ?. startsWith ( scope ) ) {
222
+ const original_url = req . url ;
222
223
req . url = req . url . slice ( scope . length ) ;
223
224
handler ( req , res , ( ) => {
224
- req . url = scope + req . url ;
225
+ req . url = original_url ;
225
226
next ( ) ;
226
227
} ) ;
227
228
} else {
0 commit comments