Skip to content

Commit c763aa8

Browse files
committed
ssr: fixes
1 parent 5c1874e commit c763aa8

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.git

src/lib/api/index.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,20 @@ const handleResponse = async (response: Response) => {
3535
}
3636
};
3737

38+
const isBrowser = typeof window !== 'undefined';
39+
3840
export const get = async (
3941
url: string,
4042
params = new URLSearchParams(),
4143
opts: { fetch?: typeof fetch } = {}
42-
) =>
43-
(opts.fetch ?? fetch)(`${BASE_URL}${url}?${params.toString()}`, {
44-
mode: 'cors',
44+
) => {
45+
return (opts.fetch ?? fetch)(`${BASE_URL}${url}?${params.toString()}`, {
46+
// for server-side rendering, use same origin policy
47+
mode: isBrowser ? 'cors' : 'same-origin',
4548
credentials: 'include',
4649
redirect: 'follow'
4750
}).then(handleResponse);
51+
};
4852

4953
export const post = async (url: string, body: any) =>
5054
fetch(`${BASE_URL}${url}`, {

src/routes/subscriptions/[id].svelte

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script context="module" lang="ts">
2+
export let prerender = false;
3+
24
import type { Load } from '@sveltejs/kit';
35
import { upcoming } from '$lib/subscriptions';
46

0 commit comments

Comments
 (0)