Added support for external APIs by extending the allowed origins

pull/313/head
abawi 8 months ago
parent 7e8650fbc0
commit 056b2cf2c9

@ -30,6 +30,7 @@ services:
- PORT=80
- REDIS_URL=redis://redis:6379
- COTURN_ENABLED=true
# - API_ORIGINS=https://example.com,https://app.example.com:3000
networks:
- filepizza
depends_on:

@ -30,6 +30,7 @@ services:
environment:
- PORT=8080
- REDIS_URL=redis://redis:6379
# - API_ORIGINS=https://example.com,https://app.example.com:3000,http://localhost:8081
networks:
- filepizza
depends_on:

@ -0,0 +1,24 @@
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
export function middleware(request: NextRequest) {
const response = NextResponse.next()
const allowedOrigins = process.env.API_ORIGINS ? process.env.API_ORIGINS.split(',') : []
const origin = request.headers.get('origin')
if (allowedOrigins.includes('*')) {
response.headers.set('Access-Control-Allow-Origin', '*')
} else if (origin && allowedOrigins.includes(origin)) {
response.headers.set('Access-Control-Allow-Origin', origin)
}
response.headers.set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, DELETE')
response.headers.set('Access-Control-Allow-Headers', 'Content-Type, Authorization')
return response
}
export const config = {
matcher: ['/:path*']
}
Loading…
Cancel
Save