Skip to content

Commit

Permalink
fix: web requests (cors!!!!) (#463)
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldietzler committed Sep 8, 2024
1 parent 19d67a7 commit 711a2b2
Show file tree
Hide file tree
Showing 21 changed files with 49 additions and 41 deletions.
7 changes: 7 additions & 0 deletions web/src/hooks.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { Handle } from '@sveltejs/kit';

export const handle = (async ({ event, resolve }) => {
return resolve(event, {
filterSerializedResponseHeaders: () => true, // basically get all headers
});
}) satisfies Handle;
7 changes: 4 additions & 3 deletions web/src/lib/utils/server.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { defaults } from '$lib/sdk/fetch-client';
import { memoize } from 'lodash-es';

function _init() {
// defaults.fetch = fetch;
defaults.baseUrl = 'http://localhost:5173/api';
type Fetch = typeof fetch;

function _init(fetch: Fetch) {
defaults.fetch = fetch;
}

export const init = memoize(_init, () => 'singlevalue');
4 changes: 2 additions & 2 deletions web/src/routes/+page.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { init } from '$lib/utils/server';
import type { PageLoad } from './$types';

export const load = (() => {
init();
export const load = (({ fetch }) => {
init(fetch);
return {
meta: {
title: 'UFTOS',
Expand Down
4 changes: 2 additions & 2 deletions web/src/routes/admin/(resources)/curriculums/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { getGrades, type Sort } from '$lib/sdk/fetch-client';
import { init } from '$lib/utils/server';
import type { PageLoad } from './$types';

export const load = (async () => {
init();
export const load = (async ({ fetch }) => {
init(fetch);
const sort: Sort = { sort: ['name,asc'] };
const grades = await getGrades(sort);

Expand Down
4 changes: 2 additions & 2 deletions web/src/routes/admin/(resources)/grades/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { init } from '$lib/utils/server';
import { error } from '@sveltejs/kit';
import type { PageLoad } from './$types';

export const load = (async () => {
init();
export const load = (async ({ fetch }) => {
init(fetch);
try {
return {
initialData: await loadGrades('', ''),
Expand Down
4 changes: 2 additions & 2 deletions web/src/routes/admin/(resources)/grades/[id]/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export const _schema = z.object({
studentGroups: z.string().array(),
});

export const load = (async ({ params }) => {
init();
export const load = (async ({ params, fetch }) => {
init(fetch);
const sort: Sort = { sort: ['name,asc'] };
const tags = await getTags(sort);
let formGrade: { id: string; name: string; studentGroups: string[]; tags: string[] }, title: string;
Expand Down
4 changes: 2 additions & 2 deletions web/src/routes/admin/(resources)/rooms/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { init } from '$lib/utils/server';
import { error } from '@sveltejs/kit';
import type { PageLoad } from './$types';

export const load = (async () => {
init();
export const load = (async ({ fetch }) => {
init(fetch);
try {
return {
initialData: await loadRoomPage('', '', 0, 15),
Expand Down
4 changes: 2 additions & 2 deletions web/src/routes/admin/(resources)/rooms/[id]/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const _schema = z.object({
tags: z.string().array(),
});

export const load = (async ({ params }) => {
init();
export const load = (async ({ params, fetch }) => {
init(fetch);
const sort: Sort = { sort: ['name,asc'] };
const tags = await getTags(sort);
let formRoom: { id: string; name: string; buildingName: string; capacity: number; tags: string[] }, title: string;
Expand Down
4 changes: 2 additions & 2 deletions web/src/routes/admin/(resources)/studentGroups/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { getGrades, getStudentGroups, getStudents } from '$lib/sdk/fetch-client'
import { init } from '$lib/utils/server';
import type { PageLoad } from './$types';

export const load = (async () => {
init();
export const load = (async ({ fetch }) => {
init(fetch);
const { totalElements: size } = await getStudentGroups({ page: 0, size: 1 });
return {
studentGroups: await getStudentGroups({ page: 0, size, sort: ['name,asc'] }).then(({ content }) => content),
Expand Down
4 changes: 2 additions & 2 deletions web/src/routes/admin/(resources)/studentGroups/[id]/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const _schema = z.object({
tags: z.string().array(),
});

export const load = (async ({ params }) => {
init();
export const load = (async ({ params, fetch }) => {
init(fetch);
const sort: Sort = { sort: ['name,asc'] };
const tags = await getTags(sort);
const subjects = await getSubjects(sort);
Expand Down
4 changes: 2 additions & 2 deletions web/src/routes/admin/(resources)/students/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { init } from '$lib/utils/server';
import { error } from '@sveltejs/kit';
import type { PageLoad } from './$types';

export const load = (async () => {
init();
export const load = (async ({ fetch }) => {
init(fetch);
try {
return {
initialData: await loadStudentPage('', '', 0, 15),
Expand Down
4 changes: 2 additions & 2 deletions web/src/routes/admin/(resources)/students/[id]/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export const _schema = z.object({
tags: z.string().array(),
});

export const load = (async ({ params }) => {
init();
export const load = (async ({ params, fetch }) => {
init(fetch);
const sort: Sort = { sort: ['name,asc'] };
const tags = await getTags(sort);
let formStudent: { id: string; firstName: string; lastName: string; tags: string[] }, title: string;
Expand Down
4 changes: 2 additions & 2 deletions web/src/routes/admin/(resources)/subjects/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { init } from '$lib/utils/server';
import { error } from '@sveltejs/kit';
import type { PageLoad } from './$types';

export const load = (async () => {
init();
export const load = (async ({ fetch }) => {
init(fetch);
try {
return {
initialData: await loadSubjects('', ''),
Expand Down
4 changes: 2 additions & 2 deletions web/src/routes/admin/(resources)/subjects/[id]/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export const _schema = z.object({
tags: z.string().array(),
});

export const load = (async ({ params }) => {
init();
export const load = (async ({ params, fetch }) => {
init(fetch);
const sort: Sort = { sort: ['name,asc'] };
const tags = await getTags(sort);
let formSubject: { id: string; name: string; tags: string[] }, title: string;
Expand Down
4 changes: 2 additions & 2 deletions web/src/routes/admin/(resources)/tags/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { init } from '$lib/utils/server';
import { error } from '@sveltejs/kit';
import type { PageLoad } from './$types';

export const load = (async () => {
init();
export const load = (async ({ fetch }) => {
init(fetch);
try {
return {
initialData: await loadTags('', ''),
Expand Down
4 changes: 2 additions & 2 deletions web/src/routes/admin/(resources)/tags/[id]/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export const _schema = z.object({
name: z.string().trim().min(1, { message: 'Der Name darf nicht leer sein.' }),
});

export const load = (async ({ params }) => {
init();
export const load = (async ({ params, fetch }) => {
init(fetch);
let tag: Tag, title: string;
if (params.id === 'new') {
tag = { id: 'new', name: '' };
Expand Down
4 changes: 2 additions & 2 deletions web/src/routes/admin/(resources)/teachers/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { init } from '$lib/utils/server';
import { error } from '@sveltejs/kit';
import type { PageLoad } from './$types';

export const load = (async () => {
init();
export const load = (async ({ fetch }) => {
init(fetch);
try {
return {
initialData: await loadTeacherPage('', '', 0, 15),
Expand Down
4 changes: 2 additions & 2 deletions web/src/routes/admin/(resources)/teachers/[id]/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const _schema = z.object({
tags: z.string().array(),
});

export const load = (async ({ params }) => {
init();
export const load = (async ({ params, fetch }) => {
init(fetch);
const sort: Sort = { sort: ['name,asc'] };
const tags = await getTags(sort);
const subjects = await getSubjects(sort);
Expand Down
4 changes: 2 additions & 2 deletions web/src/routes/admin/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { init } from '$lib/utils/server';
import { error } from '@sveltejs/kit';
import type { PageLoad } from './$types';

export const load = (async () => {
init();
export const load = (async ({ fetch }) => {
init(fetch);
try {
return {
initialGrades: await loadGrades('', ''),
Expand Down
4 changes: 2 additions & 2 deletions web/src/routes/admin/settings/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { init } from '$lib/utils/server';
import { error } from '@sveltejs/kit';
import type { PageLoad } from '../../$types';

export const load = (async () => {
init();
export const load = (async ({ fetch }) => {
init(fetch);
try {
const { email } = await getNotificationEmail();
const metadata = await getTimetableMetadata();
Expand Down
4 changes: 2 additions & 2 deletions web/src/routes/timetable/[type]/[[id]]/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { getRoomsItems, getStudentGroupsItems, getStudentsItems, getTeachersItem
import { init } from '$lib/utils/server';
import type { PageLoad } from './$types';

export const load = (async ({ params }) => {
init();
export const load = (async ({ params, fetch }) => {
init(fetch);
const type = params.type as Resource;
const resources: { [K in Resource]: ComboBoxItem[] } = { class: [], room: [], teacher: [], student: [] };

Expand Down

0 comments on commit 711a2b2

Please sign in to comment.