Code coverage report for server/app/index.js

Statements: 58.82% (10 / 17)      Branches: 0% (0 / 6)      Functions: 25% (1 / 4)      Lines: 58.82% (10 / 17)      Ignored: none     

All files » server/app/ » index.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48  1 1 1   1       2       2                 2                   2         2           2        
'use strict';
var path = require('path');
var express = require('express');
var app = express();
 
module.exports = function (db) {
 
    // Pass our express application pipeline into the configuration
    // function located at server/app/configure/index.js
    require('./configure')(app, db);
 
    // Routes that will be accessed via AJAX should be prepended with
    // /api so they are isolated from our GET /* wildcard.
    app.use('/api', require('./routes'));
 
 
    /*
     This middleware will catch any URLs resembling a file extension
     for example: .js, .html, .css
     This allows for proper 404s instead of the wildcard '/*' catching
     URLs that bypass express.static because the given file does not exist.
     */
    app.use(function (req, res, next) {
 
        if (path.extname(req.path).length > 0) {
            res.status(404).end();
        } else {
            next(null);
        }
 
    });
 
    app.get('/*', function (req, res) {
        res.sendFile(app.get('indexHTMLPath'));
    });
 
    // Error catching endware.
    app.use(function (err, req, res, next) {
        console.error(err);
        console.error(err.stack);
        res.status(err.status || 500).send(err.message || 'Internal server error.');
    });
 
    return app;
 
};