File tree Expand file tree Collapse file tree 2 files changed +20
-18
lines changed
Expand file tree Collapse file tree 2 files changed +20
-18
lines changed Original file line number Diff line number Diff line change @@ -5,19 +5,26 @@ import { ValidationPipe } from '@nestjs/common';
55async function bootstrap ( ) {
66 const app = await NestFactory . create ( AppModule ) ;
77
8+ // Configuramos CORS para que acepte localhost (desarrollo) y URL de Vercel (producción)
9+ const allowedOrigins = [
10+ 'http://localhost:5173' ,
11+ process . env . FRONTEND_URL ,
12+ ] . filter ( Boolean ) ; // Filtramos nulos por si acaso
13+
814 app . enableCors ( {
9- origin : 'http://localhost:5173' , // Solo aceptamos peticiones de este origen
15+ origin : allowedOrigins ,
1016 credentials : true ,
1117 } ) ;
1218
1319 app . useGlobalPipes (
1420 new ValidationPipe ( {
15- whitelist : true , // Filtra las propiedades que no estén definidas en el DTO
16- forbidNonWhitelisted : true , // Lanza error si envían propiedades extra (seguridad extra)
17- transform : true , // Transforma automáticamente los tipos de datos (ej. string a number)
21+ whitelist : true ,
22+ forbidNonWhitelisted : true ,
23+ transform : true ,
1824 } ) ,
1925 ) ;
2026
21- await app . listen ( process . env . PORT ?? 3000 ) ;
27+ // Render asigna dinámicamente el PORT, en tu PC usará el 3000
28+ await app . listen ( process . env . PORT || 3000 ) ;
2229}
23- bootstrap ( ) ;
30+ bootstrap ( ) ;
Original file line number Diff line number Diff line change 11import axios from 'axios' ;
22
3- // Creamos una instancia base de Axios
3+ // 1. Extraemos la URL de las variables de entorno de Vite
4+ // Si no existe (en local), usamos el fallback de siempre
5+ const BASE_URL = import . meta. env . VITE_API_URL || 'http://localhost:3000' ;
6+
47export const api = axios . create ( {
5- baseURL : 'http://localhost:3000' , // Apunta a nuestro backend de NestJS
8+ baseURL : BASE_URL ,
69 headers : {
710 'Content-Type' : 'application/json' ,
811 } ,
912} ) ;
1013
11- // EL INTERCEPTOR: Se ejecuta antes de cada petición
1214api . interceptors . request . use (
1315 ( config ) => {
14- // Buscamos el token en la bóveda del navegador
1516 const token = localStorage . getItem ( 'devtrack_token' ) ;
16-
17- // Si existe, lo inyectamos en los Headers
1817 if ( token ) {
1918 config . headers . Authorization = `Bearer ${ token } ` ;
2019 }
21-
2220 return config ;
2321 } ,
24- ( error ) => {
25- return Promise . reject ( error ) ;
26- }
27- ) ;
28-
22+ ( error ) => Promise . reject ( error )
23+ ) ;
You can’t perform that action at this time.
0 commit comments