core.io-express-server

0.1.2 • Public • Published

core.io-express

Express server module.

Config

  • port:
    • process.env.PORT
    • process.env.NODE_APP_PORT
    • 3000
  • basepath: Used to create the path to views and public.
  • locals: It will be made available to all requests through app.locals.
  • routeLocas: Specify locals per route. Example:
routeLocals: {
    '/admin': {
        layout: require('path').resolve('./modules/dashboard/views/layout.ejs')
    }
}

NOTE: Good idea to name all functions passed to app.use or router.use. Makes it easier to debug, which is true in general, since otherwise you would see <anonymous> as the output.

TODO

  • Handle unique assets, like favicon. config: { favicon: <ABSOLUTE_PATH>}
  • Provide a way to override layout for error.ejs
  • Default app: take config options
    • merge middleware
  • Asset pipeline:

Final Error Handler

For API calls:

res.send({
    success: false,
    message: error.message
});

Custom Error views

If our sub-app has the following view structure:

.
├── views
│   ├── error-layout.ejs
│   ├── 401.ejs
│   └── 403.ejs

The error view will be rendered with the following locals:

let locals = {
    isErrorView: true,
    status: status,
    message: err.message,
    error: err
};

Readme

Keywords

Package Sidebar

Install

npm i core.io-express-server

Weekly Downloads

5

Version

0.1.2

License

MIT

Unpacked Size

183 kB

Total Files

67

Last publish

Collaborators

  • goliatone