From 3c1c22a441155c84b68308cf04b098dfc39a0353 Mon Sep 17 00:00:00 2001 From: adjoly Date: Thu, 23 Oct 2025 15:54:10 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=94=A8=E3=80=8D=20fix(cors):=20f?= =?UTF-8?q?ixed=20some=20things.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/auth/default.js | 7 +++++++ src/api/user/default.js | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/src/api/auth/default.js b/src/api/auth/default.js index 422d794..5b80ed7 100644 --- a/src/api/auth/default.js +++ b/src/api/auth/default.js @@ -1,5 +1,6 @@ import fastifyJWT from '@fastify/jwt'; import fastifyCookie from '@fastify/cookie'; +import cors from '@fastify/cors'; import { register } from './register.js'; import { login } from './login.js'; @@ -24,6 +25,12 @@ authDB.prepareDB(); */ export default async function(fastify, options) { + fastify.register(cors, { + origin: process.env.CORS_ORIGIN || 'http://localhost:5173', + credentials: true, + methods: [ "GET", "POST", "PATCH", "DELETE", "OPTIONS" ] + }); + fastify.register(fastifyJWT, { secret: process.env.JWT_SECRET || '123456789101112131415161718192021', cookie: { diff --git a/src/api/user/default.js b/src/api/user/default.js index 2a3ee89..8072895 100644 --- a/src/api/user/default.js +++ b/src/api/user/default.js @@ -1,6 +1,7 @@ import fastifyJWT from '@fastify/jwt'; import fastifyCookie from '@fastify/cookie'; import Database from 'better-sqlite3'; +import cors from '@fastify/cors'; import { gUsers } from './gUsers.js'; import { gUser } from './gUser.js'; @@ -150,6 +151,11 @@ export default async function(fastify, options) { }, }); fastify.register(fastifyCookie); + fastify.register(cors, { + origin: process.env.CORS_ORIGIN || 'http://localhost:5173', + credentials: true, + methods: [ "GET", "POST", "PATCH", "DELETE", "OPTIONS" ] + }); fastify.addContentTypeParser( ['image/jpeg', 'image/png', 'image/gif', 'image/webp'],