-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
28 lines (25 loc) · 785 Bytes
/
app.js
File metadata and controls
28 lines (25 loc) · 785 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import express from 'express'
import cors from 'cors'
import cookieParser from "cookie-parser"
const app = express()
app.use(cors({
origin : process.env.CORS_ORIGIN || 'http://localhost:5173',
credentials : true
}))
app.use(express.json({limit :"16kb"}))
app.use(express.urlencoded({extended : true ,limit : "16kb"}))
app.use(express.static("public"))
app.use(cookieParser())
import userRouter from './routes/user.routes.js'
app.use('/api/v1/users',userRouter)
// Global error handler (place AFTER all routes)
app.use((err, req, res, next) => {
console.error(err);
const statusCode = err.statusCode || 500;
return res.status(statusCode).json({
success: false,
message: err.message || "Internal Server Error",
errors: err.errors || []
});
});
export {app}