fix: configure CORS to allow frontend and PWA domains

- Update backend main.ts to include www.placebo.mk in allowed origins
- Add logging to show which origins are allowed
- Set FRONTEND_URL, PWA_URL, STRAPI_URL env vars in docker-compose
- This fixes 'No Access-Control-Allow-Origin header' CORS errors
This commit is contained in:
echo 2026-02-24 19:28:54 +01:00
parent c3b01de12e
commit d573846e5c
2 changed files with 8 additions and 3 deletions

View File

@ -6,11 +6,15 @@ import { JwtAuthPublicGuard } from './modules/auth/jwt-auth-public.guard';
async function bootstrap() { async function bootstrap() {
const app = await NestFactory.create(AppModule); const app = await NestFactory.create(AppModule);
// Build allowed origins list from environment variables
const allowedOrigins = [ const allowedOrigins = [
process.env.FRONTEND_URL ?? 'http://localhost:5173', process.env.FRONTEND_URL ?? 'http://localhost:5173',
'https://www.placebo.mk', // Also allow www subdomain
process.env.PWA_URL ?? 'http://localhost:5174', process.env.PWA_URL ?? 'http://localhost:5174',
process.env.STRAPI_URL ?? 'http://localhost:1337', process.env.STRAPI_URL ?? 'http://localhost:1337',
]; ].filter(Boolean); // Remove any undefined/null values
console.log('CORS enabled for origins:', allowedOrigins);
app.enableCors({ app.enableCors({
origin: allowedOrigins, origin: allowedOrigins,

View File

@ -77,8 +77,9 @@ services:
DATABASE_LOGGING: 'false' DATABASE_LOGGING: 'false'
JWT_SECRET: ${JWT_SECRET} JWT_SECRET: ${JWT_SECRET}
JWT_EXPIRATION: '86400' JWT_EXPIRATION: '86400'
CORS_ORIGIN: https://placebo.mk,https://www.placebo.mk,https://app.placebo.mk FRONTEND_URL: https://placebo.mk
STRAPI_URL: http://cms:1337 PWA_URL: https://app.placebo.mk
STRAPI_URL: https://cms.placebo.mk
STRAPI_API_TOKEN: ${STRAPI_API_TOKEN} STRAPI_API_TOKEN: ${STRAPI_API_TOKEN}
VAPID_SUBJECT: ${VAPID_SUBJECT:-mailto:contact@placebo.mk} VAPID_SUBJECT: ${VAPID_SUBJECT:-mailto:contact@placebo.mk}
VAPID_PUBLIC_KEY: ${VAPID_PUBLIC_KEY} VAPID_PUBLIC_KEY: ${VAPID_PUBLIC_KEY}