-
Notifications
You must be signed in to change notification settings - Fork 0
/
mobile.js
executable file
·52 lines (37 loc) · 1.27 KB
/
mobile.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
var fs = require('fs');
var express = require('express');
var gzippo = require('gzippo');
var logger = require('morgan');
var handlebars = require("node-handlebars");
var CLIENT_SETTINGS_TEMPLATE_FILE = "" + __dirname + "/mobileapp/www/client.settings.template";
var CLIENT_SETTINGS_FILE = "" + __dirname + "/mobileapp/www/client.settings.js";
handlebars.create().engine(CLIENT_SETTINGS_TEMPLATE_FILE, {env: JSON.parse(JSON.stringify(process.env))}, function(err, output) {
if (err) {
throw err;
}
fs.writeFile(CLIENT_SETTINGS_FILE, output, function(err) {
if(err) {
throw err;
}
console.log(CLIENT_SETTINGS_FILE, "rendered");
});
});
var app = express();
var server = require('http').Server(app);
app.use(logger('dev'));
console.log("Starting server");
server.listen(process.env.PORT || 4000, function(){
console.log("Server started");
});
var shutdown = function(){
console.log("Shutting down server");
process.exit();
}
// TERM signal .e.g. kill
process.on('SIGTERM', shutdown);
// INT signal e.g. Ctrl-C
process.on('SIGINT', shutdown);
app.get('/', function (req, res) {
res.redirect('/kwyjibo/index.html');
});
app.use('/kwyjibo', gzippo.staticGzip("" + __dirname + "/mobileapp/www"));