-
-
Notifications
You must be signed in to change notification settings - Fork 22.6k
Closed
Description
I have too many routes in my express app, all of them are loaded when the app started.
I want to load each route only when needed.
so, I tried this approach but with no luck.
let app = Router();
app.get('/collections', getRoute('collections'));
// other routes....
function getRoute(route: string): any {
let [path, func = 'default'] = route.split(':');
console.log(`getting route: ${path}`);
return require(`./${path}`)[func];
}
collections.ts
export default (req,res)=>res.json({ok:1})
when the app starts it logs 'getting route: collections' once and in advance (even if it not accessed).
but I want to load this route only when we access the route 'api/collections'
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels