Skip to content

Commit

Permalink
[DPTM-2] Dev env (#27)
Browse files Browse the repository at this point in the history
* ar(fix) [DPTM-2]: Ensure autonomous Dev environment

* ar(fix) [DPTM-2]: Ensure autonomous Dev environment

* ar(fix) [DPTM-2]: Ensure autonomous Dev environment
  • Loading branch information
angeloreale authored Aug 8, 2024
1 parent 6f2912b commit 0fa9159
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ export const config = {
matcher: ['/api/:path*'],
};

const allowedOrigins = {
[`${process.env.MAIN_URL}`]: process.env.MAIN_URL,
[`${process.env.NEXUS_HOST}`]: process.env.NEXUS_HOST,
[`${process.env.API_HOST}`]: process.env.API_HOST,
};

const headers: Record<string, any> = {
'Access-Control-Allow-Origin': process.env.MAIN_URL || 'https://www.dreampip.com',
'Access-Control-Allow-Origin': `${process.env.MAIN_URL}` || 'https://www.dreampip.com',
'Cache-Control': 'maxage=0, s-maxage=300, stale-while-revalidate=300',
// DEV-DEBUG:
// 'content-type': 'application/json',
Expand All @@ -27,6 +33,11 @@ const headers: Record<string, any> = {
};

export default async function middleware(request: NextRequest) {
const origin = request.headers.get('x-forwarded-host') || '';
if (origin !== process.env.MAIN_URL) {
headers['Access-Control-Allow-Origin'] = allowedOrigins[origin] || 'https://www.dreampip.com';
}

// You could alternatively limit based on user ID or similar
const response = next();
const ip = ipAddress(request) || '127.0.0.1';
Expand Down

0 comments on commit 0fa9159

Please sign in to comment.