-
Notifications
You must be signed in to change notification settings - Fork 51
/
+layout.ts
27 lines (25 loc) · 1.05 KB
/
+layout.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { client } from '$lib/openapi';
import { browser } from '$app/environment';
import type { QuerySerializerOptions } from '@hey-api/client-fetch';
export const prerender = true;
if (browser) {
const params = new URL(window.location.href).searchParams;
const defaultProtocol = window.location.protocol;
const defaultHost = window.location.hostname;
const defaultPort = '8080';
const motisParam = params.get('motis');
let baseUrl = String(window.location.origin + window.location.pathname);
if (motisParam) {
if (/^[0-9]+$/.test(motisParam)) {
baseUrl = defaultProtocol + '//' + defaultHost + ':' + motisParam;
} else if (!motisParam.includes(':')) {
baseUrl = defaultProtocol + '//' + motisParam + ':' + defaultPort;
} else if (!motisParam.startsWith('http:') && !motisParam.startsWith('https:')) {
baseUrl = defaultProtocol + '//' + motisParam;
} else {
baseUrl = motisParam;
}
}
const querySerializer = { array: { explode: false } } as QuerySerializerOptions;
client.setConfig({ baseUrl, querySerializer }); //`${window.location}`
}