Merge pull request #45 from KeyZox71/test-fix-apis

🔨」 fix(cors issue): should be working as expected (closes #44)
This commit is contained in:
Adam
2025-10-15 17:32:01 +02:00
committed by GitHub
4 changed files with 13 additions and 1 deletions

View File

@ -24,3 +24,5 @@ SMTP_FROM=<the address to send from>
SMTP_AUTH_USERNAME=<smtp-user>
SMTP_AUTH_PASSWORD=<smtp pass>
EMAIL_TO=<mail to send to>
CORS_ORIGIN=<the url of origin for cors>

View File

@ -15,6 +15,7 @@ services:
- API_TARGET=user
- LOG_FILE_PATH=/var/log/log.log
- JWT_SECRET=${JWT_SECRET}
- CORS_ORIGIN=${CORS_ORIGIN}
restart: unless-stopped
auth-api:
container_name: transcendence-api-auth
@ -35,6 +36,7 @@ services:
- API_TARGET=auth
- LOG_FILE_PATH=/var/log/log.log
- JWT_SECRET=${JWT_SECRET}
- CORS_ORIGIN=${CORS_ORIGIN}
restart: unless-stopped
scorestore-api:
container_name: transcendence-api-scoreStore

View File

@ -24,7 +24,7 @@ authDB.prepareDB();
export default async function(fastify, options) {
fastify.register(cors, {
origin: "http://localhost:5173",
origin: process.ENV.CORS_ORIGIN || 'http://localhost:5173',
credentials: true,
methods: [ "GET", "POST", "DELETE", "OPTIONS" ]
});

View File

@ -1,5 +1,6 @@
import fastifyJWT from '@fastify/jwt';
import fastifyCookie from '@fastify/cookie';
import cors from '@fastify/cors'
import Database from 'better-sqlite3';
var env = process.env.NODE_ENV || 'development';
@ -56,6 +57,13 @@ const deleteFriends = database.prepare('DELETE FROM friends WHERE username = ?;'
* @param {import('fastify').FastifyPluginOptions} options
*/
export default async function(fastify, options) {
fastify.register(cors, {
origin: process.ENV.CORS_ORIGIN || 'http://localhost:5173',
credentials: true,
methods: [ "GET", "POST", "DELETE", "OPTIONS" ]
});
fastify.register(fastifyJWT, {
secret: process.env.JWT_SECRET || '123456789101112131415161718192021',
cookie: {