-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.js
36 lines (28 loc) · 864 Bytes
/
routes.js
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
29
30
31
32
33
34
35
36
import express from "express";
import userRouter from "./src/features/users/user.router.js";
import authRouter from "./src/features/authSocial/auth.router.js";
const router = express.Router();
router.get('/', (req, res) => {
return res.status(200).json({
message: "Welcome to the Home Page!",
status: true
})
})
router.use('/api/user', userRouter);
// google router
router.use('/api/auth', authRouter)
// middleware to handle routes not found
router.use((req, res) => {
return res.status(404).json({
message: "APIs not found",
status: false
})
})
// Example of a protected route
router.get('/profile', (req, res) => {
if (!req.isAuthenticated()) {
return res.status(401).json({ message: 'Unauthorized' });
}
res.json({ message: `Hello, ${req.user.name}` });
});
export default router;