This repository has been archived by the owner on Aug 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·94 lines (69 loc) · 2.6 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
var express = require('express');
var harp = require('harp');
var app = express();
var harpMiddleware = require('./node_modules/harp/lib/middleware');
var path = require('path');
var logger = require('./lib/logger');
var config = require('config');
var serverConfig = config.get('server');
// Default server configuration in case
// no config files are present
var defaultServerConfig = {
serveUnderscores: true,
appRoot: 'src/',
port: 9000
};
module.exports = createApp;
/**
* Create express application
*
* @param options
* @returns {*}
*/
function createApp (options) {
// Merge configuration with server defaults
config.util.extendDeep(defaultServerConfig, options)
config.util.setModuleDefaults('server', defaultServerConfig);
var appRoot = path.resolve(__dirname, serverConfig.appRoot);
/**************************************************************************
* Ignore files if needed
*************************************************************************/
if(serverConfig.serveUnderscores !== true){
app.use(harpMiddleware.underscore);
}
/**************************************************************************
* Configure logger
*************************************************************************/
app.use(logger());
/**************************************************************************
* Serve static assets
*************************************************************************/
app.use(express.static(appRoot));
/**************************************************************************
* Let harp serve application
*************************************************************************/
app.use(harp.mount(appRoot));
/**************************************************************************
* Handle unfound .js, .js.map and .css requests with 404
* to prevent html from being returned by catch all
*************************************************************************/
app.all(/.*\.(js|css|js\.map)$/i, function(req, res, next){
res.status(404).send('Not Found');
});
/**************************************************************************
* Let 200.jade catch all other requests
*************************************************************************/
app.use(harpMiddleware.fallback);
return app;
}
/**
* Start the application if module is called
* directly and not required by other module
*/
if(require.main === module){
var server = createApp();
var port = serverConfig.port;
server.listen(port, function(){
console.log('Angular Express running on port %s', port);
});
}