Replies: 1 comment
-
What you might want is let app = Router();
app.get('/collections', getRoute('collections'));
// other routes....
function getRoute(route: string): any {
let [path, func = 'default'] = route.split(':');
let fn = null;
return (req, res, next) => {
if(fn == null) fn = require(`./${path}`)[func];
return fn(req, res, next);
};
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
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.
collections.ts
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'
Beta Was this translation helpful? Give feedback.
All reactions