core.io-express-server
v0.1.2
Published
core.io Express server module
Downloads
59
Readme
core.io-express
Express server module.
Config
port
:process.env.PORT
process.env.NODE_APP_PORT
- 3000
basepath
: Used to create the path toviews
andpublic
.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:
- mincer package
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
};