Reputation: 515
I have my code
app.set('views', path..);
originally placed in server.js
and I tried to segregate/factor it into a config.server.js (see link), there I implemented underscoreJS
each to loop through the modules by their folders' names in my modules/
directory. ['core', 'xt_syncs']. Problem with this trick I try playing is that, app.set('views',..)
can't be a Singleton (which loads many things at once). The app.set('views',..)
can only have 1 URI for 'views' (module specific, my app contains several modules: core, xt_syncs as you see in the structure), and the app.set
appear to fail, and be overwritten by the static uri to modules/second_module.
I write the app myself, picking the middlewares/components I want. I'm trying to reuse some of the assets from MEANjs, mean-stack-relational (MVC, I prefer modules architecture to MVC, that's why my attempt is to build mine), and SEANjs (quite too complex, the stack requires Redis and MySQL5.7, I try building mine so I can get a good understanding of things flow on the fly and exclude Redis and MySQL upgrade).
Now back to the question, obviously, you see in MEANjs and SEANjs , they do in their default.js file:
views: ['modules/*/client/views/**/*.html'],
routes: ['modules/!(core)/server/routes/**/*.js', 'modules/core/server/routes/**/*.js']
QUESTIONS:
1/ How can I implement similar pattern in my app? Notice in the MEANjs and SEANjs, there is *
as in modules/*/client
and !
as in modules/!(core)/server
. app design advices and coding help, please. (this part of the question is not yet addressed)
2/ How related the default.js
is to the config.js (initGlobalConfigFolders,initGlobalConfigFiles,...)? I try to wrap my head around to understand config.js and find clues of the glueing. Maybe, my modules[module] as in
modules[module] = {
client: {},
server: {}
};
is one step closer to what they built in the initGlobalConfigFolders method.
3/ Is using build tool (Grunt, Gulp, or Webpack) a must here to achieve that? If so, Can you show me how? (build tool incorporation is in my planning). How can you
Thank you very much.
Upvotes: 1
Views: 128
Reputation: 515
app.set('views', view_paths);
// where view_paths can be an array of views folders.2 & 3. Awaiting help and answers.
Upvotes: 0