@@ -8,15 +8,42 @@ import { eventRouter } from "./modules/event";
88import { homeRouter } from "./modules/home" ;
99import { userRouter } from "./modules/user" ;
1010
11+ const port = env . PORT ?? Number ( process . env . PORT ) ?? 3000 ;
12+
1113const app = new Elysia ( )
12- . use ( cors ( { origin : env . CORS_ORIGIN , credentials : true } ) )
14+ . onError ( ( { code, error, set } ) => {
15+ console . error ( `Error [${ code } ]:` , error ) ;
16+
17+ if ( code === "VALIDATION" ) {
18+ set . status = 400 ;
19+ return { error : "Validation Error" , message : error . toString ( ) } ;
20+ }
21+
22+ set . status = 500 ;
23+ return { error : "Internal Server Error" , message : error . toString ( ) } ;
24+ } )
25+ . use (
26+ cors ( {
27+ origin : [
28+ "https://eventer-web-git-feat-implement-ge-0f5106-methasit-puns-projects.vercel.app" ,
29+ "https://eventer-web-red.vercel.app" , // optionally add production URL
30+ "http://localhost:3000" , // for local development
31+ / .* \. v e r c e l \. a p p $ / , // Allow all Vercel preview deployments
32+ ] ,
33+ credentials : true ,
34+ } )
35+ )
1336 . use ( swagger ( ) )
1437 . group ( "/api" , ( app ) =>
1538 app . use ( homeRouter ) . use ( eventRouter ) . use ( userRouter ) . use ( agendaRouter ) . use ( authRouter )
16- )
17- . listen ( env . PORT , ( ) => {
18- console . log ( `Server is running on http://localhost:${ env . PORT } /api` ) ;
39+ ) ;
40+
41+ // Only listen if not in serverless environment (for local development)
42+ if ( process . env . NODE_ENV !== "production" && ! process . env . VERCEL ) {
43+ app . listen ( port , ( ) => {
44+ console . log ( `Server is running on http://localhost:${ port } /api` ) ;
1945 } ) ;
46+ }
2047
2148export { app } ;
2249export type AppType = typeof app ;
0 commit comments