@@ -8,7 +8,6 @@ import { getRequest, setResponse } from '../../../exports/node/index.js';
8
8
import { installPolyfills } from '../../../exports/node/polyfills.js' ;
9
9
import { SVELTE_KIT_ASSETS } from '../../../constants.js' ;
10
10
import { should_polyfill } from '../../../utils/platform.js' ;
11
- import { not_found } from '../utils.js' ;
12
11
13
12
/** @typedef {import('http').IncomingMessage } Req */
14
13
/** @typedef {import('http').ServerResponse } Res */
@@ -54,42 +53,15 @@ export async function preview(vite, vite_config, svelte_config) {
54
53
} ) ;
55
54
56
55
return ( ) => {
57
- // generated client assets and the contents of `static`
58
- vite . middlewares . use (
59
- scoped (
60
- assets ,
61
- sirv ( join ( svelte_config . kit . outDir , 'output/client' ) , {
62
- setHeaders : ( res , pathname ) => {
63
- // only apply to immutable directory, not e.g. version.json
64
- if ( pathname . startsWith ( `/${ svelte_config . kit . appDir } /immutable` ) ) {
65
- res . setHeader ( 'cache-control' , 'public,max-age=31536000,immutable' ) ;
66
- }
67
- }
68
- } )
69
- )
70
- ) ;
71
-
72
- vite . middlewares . use ( ( req , res , next ) => {
73
- const original_url = /** @type {string } */ ( req . url ) ;
74
- const { pathname } = new URL ( original_url , 'http://dummy' ) ;
75
-
76
- if ( pathname . startsWith ( base ) ) {
77
- next ( ) ;
78
- } else {
79
- res . statusCode = 404 ;
80
- not_found ( req , res , base ) ;
81
- }
82
- } ) ;
83
-
84
56
// prerendered dependencies
85
57
vite . middlewares . use (
86
- scoped ( base , mutable ( join ( svelte_config . kit . outDir , 'output/prerendered/dependencies' ) ) )
58
+ mutable ( join ( svelte_config . kit . outDir , 'output/prerendered/dependencies' ) )
87
59
) ;
88
60
89
61
// prerendered pages (we can't just use sirv because we need to
90
62
// preserve the correct trailingSlash behaviour)
91
63
vite . middlewares . use (
92
- scoped ( base , ( req , res , next ) => {
64
+ ( req , res , next ) => {
93
65
let if_none_match_value = req . headers [ 'if-none-match' ] ;
94
66
95
67
if ( if_none_match_value ?. startsWith ( 'W/"' ) ) {
@@ -149,18 +121,17 @@ export async function preview(vite, vite_config, svelte_config) {
149
121
} else {
150
122
next ( ) ;
151
123
}
152
- } )
124
+ }
153
125
) ;
154
126
155
127
// SSR
156
128
vite . middlewares . use ( async ( req , res ) => {
157
129
const host = req . headers [ 'host' ] ;
158
130
159
131
let request ;
160
-
161
132
try {
162
133
request = await getRequest ( {
163
- base : `${ protocol } ://${ host } ` ,
134
+ base : new URL ( base , `${ protocol } ://${ host } ` ) . href ,
164
135
request : req
165
136
} ) ;
166
137
} catch ( /** @type {any } */ err ) {
@@ -195,28 +166,6 @@ const mutable = (dir) =>
195
166
} )
196
167
: ( _req , _res , next ) => next ( ) ;
197
168
198
- /**
199
- * @param {string } scope
200
- * @param {Handler } handler
201
- * @returns {Handler }
202
- */
203
- function scoped ( scope , handler ) {
204
- if ( scope === '' ) return handler ;
205
-
206
- return ( req , res , next ) => {
207
- if ( req . url ?. startsWith ( scope ) ) {
208
- const original_url = req . url ;
209
- req . url = req . url . slice ( scope . length ) ;
210
- handler ( req , res , ( ) => {
211
- req . url = original_url ;
212
- next ( ) ;
213
- } ) ;
214
- } else {
215
- next ( ) ;
216
- }
217
- } ;
218
- }
219
-
220
169
/** @param {string } path */
221
170
function is_file ( path ) {
222
171
return fs . existsSync ( path ) && ! fs . statSync ( path ) . isDirectory ( ) ;
0 commit comments