File tree Expand file tree Collapse file tree 5 files changed +35
-21
lines changed
Expand file tree Collapse file tree 5 files changed +35
-21
lines changed Original file line number Diff line number Diff line change 11import passport from "passport" ;
22
3- const JwtTokenValidador = passport . authenticate ( "jwt" , { session : false } ) ;
3+ const getJwtTokenValidador = ( ) => {
4+ return passport . authenticate ( "jwt" , { session : false } ) ;
5+ } ;
46
5- export { JwtTokenValidador } ;
7+ export { getJwtTokenValidador } ;
Original file line number Diff line number Diff line change 11import { signIn , signUp , verifyAccount } from "../controllers/authControllers" ;
22import { Router } from "express" ;
33
4- const router = Router ( ) ;
4+ const getAuthRouter = ( ) => {
5+ const router = Router ( ) ;
56
6- router . post ( "/signup" , signUp ) ;
7+ router . post ( "/signup" , signUp ) ;
78
8- router . post ( "/signin" , signIn ) ;
9+ router . post ( "/signin" , signIn ) ;
910
10- router . get ( "/emailconfirmation/:token" , verifyAccount ) ;
11+ router . get ( "/emailconfirmation/:token" , verifyAccount ) ;
1112
12- export { router as authRoutes } ;
13+ return router ;
14+ } ;
15+
16+ export { getAuthRouter } ;
Original file line number Diff line number Diff line change 11import { about } from "../../api/controllers/homeControllers" ;
22import { Router } from "express" ;
33
4- const router = Router ( ) ;
4+ const getHomeRouter = ( ) => {
5+ const router = Router ( ) ;
56
6- router . get ( "/about" , about ) ;
7+ router . get ( "/about" , about ) ;
78
8- export { router as homeRoutes } ;
9+ return router ;
10+ } ;
11+
12+ export { getHomeRouter } ;
Original file line number Diff line number Diff line change 11import { profile } from "../../api/controllers/userControllers" ;
22import { Router } from "express" ;
3- import { JwtTokenValidador } from "../middlewares/jwtTokenValidador" ;
3+ import { getJwtTokenValidador } from "../middlewares/jwtTokenValidador" ;
44
5- const router = Router ( ) ;
5+ const getUserRouter = ( ) => {
6+ const router = Router ( ) ;
67
7- //As '/profile' is a protected route, we have to pass the JwtTokenValidador first as middleware before it arrives to the profile function.
8- router . get ( "/profile" , JwtTokenValidador , profile ) ;
8+ //As '/profile' is a protected route, we have to pass the JwtTokenValidador first as middleware before it arrives to the profile function.
9+ router . get ( "/profile" , getJwtTokenValidador ( ) , profile ) ;
910
10- export { router as userRoutes } ;
11+ return router ;
12+ } ;
13+
14+ export { getUserRouter } ;
Original file line number Diff line number Diff line change @@ -4,11 +4,11 @@ import morgan from "morgan";
44import helmet from "helmet" ;
55import cookieParser from "cookie-parser" ;
66import { configurePassportMiddlewares } from "./passportConfig" ;
7- import { authRoutes } from "../api/routers/authRouter" ;
7+ import { getAuthRouter } from "../api/routers/authRouter" ;
88import config from "./envConfig" ;
99import cors from "cors" ;
10- import { userRoutes } from "../api/routers/userRoutes" ;
11- import { homeRoutes } from "../api/routers/homeRoutes" ;
10+ import { getUserRouter } from "../api/routers/userRoutes" ;
11+ import { getHomeRouter } from "../api/routers/homeRoutes" ;
1212
1313const app : Application = express ( ) ;
1414
@@ -33,9 +33,9 @@ configurePassportMiddlewares();
3333//#endregion
3434
3535//#region Routes
36- app . use ( "/api/home/" , homeRoutes ) ;
37- app . use ( "/api/auth" , authRoutes ) ;
38- app . use ( "/api/user/" , userRoutes ) ;
36+ app . use ( "/api/home/" , getHomeRouter ( ) ) ;
37+ app . use ( "/api/auth" , getAuthRouter ( ) ) ;
38+ app . use ( "/api/user/" , getUserRouter ( ) ) ;
3939
4040//#endregion
4141export default app ;
You can’t perform that action at this time.
0 commit comments