@@ -5,34 +5,31 @@ import router from "./routes/router";
55import cookieParser from "cookie-parser" ;
66import cors from "cors" ;
77
8- // Load environment variables
98dotenv . config ( ) ;
109const PORT = Number ( process . env . PORT ) || 4000 ;
1110const app = express ( ) ;
1211app . use ( express . json ( ) ) ;
1312
1413app . use ( cookieParser ( ) ) ;
1514
16- // CORS options
1715const corsOptions = {
1816 origin :
1917 process . env . NODE_ENV === "production"
2018 ? [
2119 "https://blog-content-management-demo.vercel.app" ,
2220 "https://blogcontentmanagement.netlify.app" ,
23- ...( process . env . FRONTEND_URL ? [ process . env . FRONTEND_URL ] : [ ] ) , // Add custom frontend URL if provided
21+ ...( process . env . FRONTEND_URL ? [ process . env . FRONTEND_URL ] : [ ] ) ,
2422 ]
25- : true , // Allow all origins in development
26- credentials : true , // allow cookies to be sent
27- methods : [ "GET" , "POST" , "PUT" , "DELETE" , "OPTIONS" ] , // Explicitly allow methods
28- allowedHeaders : [ "Content-Type" , "Authorization" , "Cookie" ] , // Allow headers including cookies
29- optionsSuccessStatus : 200 , // For legacy browser support
23+ : true ,
24+ credentials : true ,
25+ methods : [ "GET" , "POST" , "PUT" , "DELETE" , "OPTIONS" ] ,
26+ allowedHeaders : [ "Content-Type" , "Authorization" , "Cookie" ] ,
27+ optionsSuccessStatus : 200 ,
3028} ;
3129
3230app . use ( cors ( corsOptions ) ) ;
3331app . use ( morgan ( "combined" ) ) ;
3432
35- // Health check endpoint
3633app . get ( "/health" , ( req , res ) => {
3734 res . status ( 200 ) . json ( {
3835 status : "OK" ,
@@ -45,8 +42,8 @@ app.get("/health", (req, res) => {
4542app . use ( "/api" , router ) ;
4643
4744app . listen ( PORT , "0.0.0.0" , ( ) => {
48- console . log ( `🚀 App is running and listening on port: ${ PORT } ` ) ;
49- console . log ( `🌍 Environment: ${ process . env . NODE_ENV || "development" } ` ) ;
50- console . log ( `🍪 Cookie domain: ${ process . env . COOKIE_DOMAIN || "not set" } ` ) ;
51- console . log ( `🔗 Frontend URL: ${ process . env . FRONTEND_URL || "not set" } ` ) ;
45+ console . log ( `App is running and listening on port: ${ PORT } ` ) ;
46+ console . log ( `Environment: ${ process . env . NODE_ENV || "development" } ` ) ;
47+ console . log ( `Cookie domain: ${ process . env . COOKIE_DOMAIN || "not set" } ` ) ;
48+ console . log ( `Frontend URL: ${ process . env . FRONTEND_URL || "not set" } ` ) ;
5249} ) ;
0 commit comments