run(callbacks={}) {
        utils.logdebug(`* Running in ${process.env.NODE_ENV || 'development'} mode`)
        let _port = this.getServerPort();
        const app = this.app;
        //app.use(bodyParser.urlencoded({extended: false}));
        // set routes
        app.use(this.getApiRootPath(),this.dynamicRoutes.getRouter());
        utils.logdebug(`* Setted up Api Routes.`);
        app.use('*',(req,res) => {
            res.status(404).send({ error: 'Wrong request url' });
            if (req.originalUrl != '/favicon.ico')
                console.log('Requested wrong url: '+req.originalUrl)
        })
        utils.logdebug(`* Setted up wrong url response.`);
        app.use(function(err, req, res, next) {
            if (typeof callbacks.onError === 'function') 
                callbacks.onError(err, req, res);
            else {
                res.status(500).send({ error: 'Something failed!' });
                res.locals.error = err;
                const status = err.status || 500;
                res.status(status);
                res.render('error');
            }
            console.log('Request failed:',err)
        })
        utils.logdebug(`* Setted up error handler.`);
        app.listen(_port, function() {
            console.log(`Express Server is up on port ${_port}`);
        })
    }
/**
     * Setup Express app adding router, handling wrong path and errors.
     * Start Express Server at configured or default port
     * @param {*} callbacks usefull to capture Express errors ( TODO: add callbacks and take them from config )
     */
Setup Express app adding router, handling wrong path and errors.
Start Express Server at configured or default port
@param {*} callbacks usefull to capture Express errors ( TODO: add callbacks and take them from config )
Setup Express app adding router handling wrong path and errors . Start Express Server at configured or default port @param { * } callbacks usefull to capture Express errors ( TODO : add callbacks and take them from config )
run(callbacks={}) {
        utils.logdebug(`* Running in ${process.env.NODE_ENV || 'development'} mode`)
        let _port = this.getServerPort();
        const app = this.app;
        app.use(this.getApiRootPath(),this.dynamicRoutes.getRouter());
        utils.logdebug(`* Setted up Api Routes.`);
        app.use('*',(req,res) => {
            res.status(404).send({ error: 'Wrong request url' });
            if (req.originalUrl != '/favicon.ico')
                console.log('Requested wrong url: '+req.originalUrl)
        })
        utils.logdebug(`* Setted up wrong url response.`);
        app.use(function(err, req, res, next) {
            if (typeof callbacks.onError === 'function') 
                callbacks.onError(err, req, res);
            else {
                res.status(500).send({ error: 'Something failed!' });
                res.locals.error = err;
                const status = err.status || 500;
                res.status(status);
                res.render('error');
            }
            console.log('Request failed:',err)
        })
        utils.logdebug(`* Setted up error handler.`);
        app.listen(_port, function() {
            console.log(`Express Server is up on port ${_port}`);
        })
    }
run ( callbacks = { } ) { utils . logdebug ( ` ${ process . env . NODE_ENV || 'development' } ` ) let _port = this . getServerPort ( ) ; const app = this . app ; app . use ( this . getApiRootPath ( ) , this . dynamicRoutes . getRouter ( ) ) ; utils . logdebug ( ` ` ) ; app . use ( '*' , ( req , res ) => { res . status ( 404 ) . send ( { error : 'Wrong request url' } ) ; if ( req . originalUrl != '/favicon.ico' ) console . log ( 'Requested wrong url: ' + req . originalUrl ) } ) utils . logdebug ( ` ` ) ; app . use ( function ( err , req , res , next ) { if ( typeof callbacks . onError === 'function' ) callbacks . onError ( err , req , res ) ; else { res . status ( 500 ) . send ( { error : 'Something failed!' } ) ; res . locals . error = err ; const status = err . status || 500 ; res . status ( status ) ; res . render ( 'error' ) ; } console . log ( 'Request failed:' , err ) } ) utils . logdebug ( ` ` ) ; app . listen ( _port , function ( ) { console . log ( ` ${ _port } ` ) ; } ) }
Setup Express app adding router, handling wrong path and errors.
Setup Express app adding router handling wrong path and errors .
//app.use(bodyParser.urlencoded({extended: false})); // set routes