|
1 | 1 | import { base, assets, relative, initial_base } from './internal/server.js'; |
2 | 2 | import { resolve_route, exec } from '../../../utils/routing.js'; |
3 | | -import { decode_params } from '../../../utils/url.js'; |
| 3 | +import { decode_params, decode_pathname } from '../../../utils/url.js'; |
4 | 4 | import { try_get_request_store } from '@sveltejs/kit/internal/server'; |
5 | 5 | import { manifest } from '__sveltekit/server'; |
| 6 | +import { get_hooks } from '__SERVER__/internal.js'; |
6 | 7 |
|
7 | 8 | /** @type {import('./client.js').asset} */ |
8 | 9 | export function asset(file) { |
@@ -31,16 +32,29 @@ export function resolve(id, params) { |
31 | 32 |
|
32 | 33 | /** @type {import('./client.js').match} */ |
33 | 34 | export async function match(pathname) { |
34 | | - let path = pathname; |
| 35 | + const store = try_get_request_store(); |
| 36 | + const origin = store?.event.url.origin ?? 'http://sveltekit'; |
| 37 | + const url = new URL(pathname, origin); |
35 | 38 |
|
36 | | - if (base && path.startsWith(base)) { |
37 | | - path = path.slice(base.length) || '/'; |
| 39 | + const { reroute } = await get_hooks(); |
| 40 | + |
| 41 | + let resolved_path = |
| 42 | + (await reroute?.({ url, fetch: store?.event.fetch ?? fetch })) ?? url.pathname; |
| 43 | + |
| 44 | + try { |
| 45 | + resolved_path = decode_pathname(resolved_path); |
| 46 | + } catch { |
| 47 | + return null; |
| 48 | + } |
| 49 | + |
| 50 | + if (base && resolved_path.startsWith(base)) { |
| 51 | + resolved_path = resolved_path.slice(base.length) || '/'; |
38 | 52 | } |
39 | 53 |
|
40 | 54 | const matchers = await manifest._.matchers(); |
41 | 55 |
|
42 | 56 | for (const route of manifest._.routes) { |
43 | | - const match = route.pattern.exec(path); |
| 57 | + const match = route.pattern.exec(resolved_path); |
44 | 58 | if (!match) continue; |
45 | 59 |
|
46 | 60 | const matched = exec(match, route.params, matchers); |
|
0 commit comments