mns-fe-server
This module is a wrapper around the node Express.js server. It takes a single configuration object with the following properties:
Name | Type | Description |
---|
assetsDir | string | Dir to serve static files such as images, CSS files, and JavaScript files |
jsonLogging | function | Function used for logging events, can be used with @mands/mns-fe-foundation/src/components/logger |
logger | boolean | Enable or Disable logging |
routesDir | function | A function that returns the path to the routes directory |
handlebars | object | Handlebars view engine object |
pageNotFoundHandler | function | A mapping to a handler for 404 status events |
errorPageHandler | function | A mapping to a handler for 500 status events |
ExposeRoutes | function | Function which returns a dir with the exposed routes |
Install the server:
npm install --save @mands/mns-fe-server
Include the module and start:
const config = require('./configuration/server')
let server = require('@mands/mns-fe-server')(config)
server.start()
Here's an example configuration object to get you started:
module.exports = {
routesDir: (server) => {
server.get('/', (req, res) => {
res.end('Hello world');
});
},
assetsDir: '/assets',
ExposeRoutes: require('mns-core-ui-header').ExposeRoutes,
logger: false,
jsonLogging: () => {
return (req, res, next) => {
next();
};
},
pageNotFoundHandler: (req, res) => {
res.send('M&S - 404 Error');
},
errorPageHandler: (req, res) => {
res.send('M&S - 500 Error');
},
handlebars: {
viewsDir: __dirname + '/views/pages',
partialsDir: [
__dirname + '/views/partials',
__dirname + '/views/partials/layouts',
{
dir: 'node_modules/mns-core-ui/dist/templates/navigation/partials',
namespace: 'templates/navigation/partials'
}
]
}
};