This commit is contained in:
2025-06-08 19:49:32 +02:00
parent 482285abf6
commit 7a8bcca0ef
5 changed files with 59 additions and 11 deletions

View File

@@ -1,14 +1,23 @@
import type { Actions } from '@sveltejs/kit';
const BACKEND_URL: string = 'http://127.0.0.1:3000' as const;
import { fail, type Actions } from '@sveltejs/kit';
import { PUBLIC_BACKEND_URL } from '$env/static/public';
import { AUTH_COOIKIE_NAME } from '$lib/auth';
export const actions = {
'send-message': async ({request, fetch}) => {
'send-message': async ({ request, fetch, cookies }) => {
const authToken = cookies.get(AUTH_COOIKIE_NAME);
if (authToken == null) {
return fail(400);
}
const formData = await request.formData();
const response = await fetch(`${BACKEND_URL}/message`, {
const response = await fetch(`${PUBLIC_BACKEND_URL}/message`, {
method: 'POST',
body: formData,
headers: {
authorization: `Bearer ${authToken}`
},
body: formData
});
},
}
} satisfies Actions;