ezzy-express-mvc
A complete mvc infrastructure to render pages from a specific directory.
You can use this class to recurse through a directory that contains Controllers, Models and Views to prepare an application with multiple routes mapped accordingly. This utility maps all controllers to their respective views and provides the necessary models to generate the response.
When the application initializes, an instance to the controller is
registered in the express application. Then, at the time of the request,
an instance of the respective model gets injected into the view of the
application. While the model is injected, the code checks for any JS and CSS
assets that exist in the respective assets directory. During production,
this directory is only checked once, but in development, the directory
is checked on every request. Additionally, sass and compass have been
implemented to allow dynamic CSS generation to the corresponding /css
folder.
For example, you can structure your directory in this manner:
- /src/ (root)
http://localhost:9000/
- /src/HomeController.js (home app)
- /src/HomeModel.js
- /src/homeView.hbs
- /src/homeAssets/ (home app static assets)
- /src/homeAssets/js/
- /src/homeAssets/css/
- /src/homeAssets/images/
- /src/homeAssets/scss/ (home app sass/compass sources)
http://localhost:9000/login/
- /src/login/LoginController.js (login app)
- /src/login/LoginModel.js
- /src/login/loginView.hbs
- /src/login/loginAssets/ (login app static assets)
- /src/login/loginAssets/js/
- /src/login/loginAssets/css/
- /src/login/loginAssets/images/
Other Utilities
- /src/partials/customPartial.hbs (other handlebars tools)
- /src/layouts/baseLayout.hbs
- /src/helpers/customHelper.hbs
And now in your localhost.js file, you can simply invoke it like this:
const ExpressMvc = ;__dirname + '/src' promise // we have to wait for file detection. ;
If you'd like to bind other applications to the same port, simply use:
const ExpressMvc = ;__dirname + '/src' promise ;
Constructor Configuration
/** * @param * @param * @param {function({HttpBasics}):boolean} requestFilter The filter function that decides if this instance of the MVC application will handle the request. * @param * @param * @param * @param * @param * @param * @param * @param * @param * @param * @param * @param */ const defaultConfig = directory: undefined middleware: undefined domainReg: /.*/ statics: undefined bind404: false requestFilter: undefined customErrorDir: 'errors' globalMiddleware: undefined expressDependency: undefined partials: undefined layouts: undefined helpersFile: undefined partialsDirectories: layoutsDirectories: otherStatics: ;