feat(POS-FIX-6): completed feature
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
// Use same host as browser to preserve cookies. In production, use the actual backend URL.
|
||||
// Resuelve la URL del backend:
|
||||
// 1. POS_BACKEND_URL: explícito (dev por IP LAN, prod con traefik en otro host)
|
||||
// 2. Mismo origen que el navegador: funciona en dev local y prod detrás de traefik
|
||||
// (traefik sirve frontend+backend en el mismo dominio, routando /api/* al backend)
|
||||
function getBackendUrl(request: NextRequest): string {
|
||||
if (process.env.POS_BACKEND_URL) {
|
||||
return `${process.env.POS_BACKEND_URL}/${apiPath(request)}${request.nextUrl.search}`;
|
||||
const backendUrl = process.env.POS_BACKEND_URL;
|
||||
if (backendUrl) {
|
||||
const base = backendUrl.replace(/\/$/, '');
|
||||
return `${base}/${apiPath(request)}${request.nextUrl.search}`;
|
||||
}
|
||||
// Dev: use same host/port as browser to keep cookies working
|
||||
// Fallback: mismo origen que el navegador (dev local y prod traefik)
|
||||
const protocol = request.headers.get('x-forwarded-proto') ?? request.nextUrl.protocol;
|
||||
const host = request.headers.get('x-forwarded-host') ?? request.nextUrl.host;
|
||||
return `${protocol}//${host}/${apiPath(request)}${request.nextUrl.search}`;
|
||||
|
||||
Reference in New Issue
Block a user