-
Notifications
You must be signed in to change notification settings - Fork 108
/
server.js
executable file
·74 lines (62 loc) · 1.81 KB
/
server.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
/**
* Server - This is the Node.js Server.
* @object
*/
var fs = require('fs'),
cmsRouter = require('./routes/cms-router.js'),
path = require('path'),
serveStatic = require('serve-static'),
config = JSON.parse(fs.readFileSync('./config/config.json'));
//Test if services
if (process.env.VCAP_SERVICES) {
var cloudServices = JSON.parse(process.env.VCAP_SERVICES);
console.warn('cloud services', cloudServices);
//var dbcreds = services['mongodb'][0].credentials;
}
var port = process.env.PORT || config.port;
var host = process.env.VCAP_APP_HOST || "127.0.0.1";
config.host = host;
config.port = port;
var express = require('express');
var app = express();
var router = new cmsRouter(config, app);
router.mount();
var options = {
dotfiles: 'ignore',
etag: false,
extensions: [
'js',
'png',
'html', 'jpeg', 'jpg', 'gif',
'css'
],
index: true,
maxAge: '1d',
redirect: false,
setHeaders: function(res, path) {
res.set('x-timestamp', Date.now());
}
};
var staticDir = config.publicDir;
console.log('staticDir', staticDir);
//app.use(express.static(config.publicDir));
//app.use(express.static(config.staticDir));
//app.use(express.static('www'));
app.use(express.static('app'));
app.use('/www', express.static('./www'));
app.use(express.static(path.resolve(__dirname, config.staticDir), options));
app.all('/', function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'X-Requested-With');
next();
console.log('cms-server', req.method);
});
app.get('/', function(res, req, next) {
var indexFile = config.publicDir + path.sep + 'index.html';
console.log('Loading index', indexFile);
req.sendFile(indexFile);
next();
});
app.listen(port, function() {
console.log('express server listening on port: ' + port);
});