forked from codeforgermany/click_that_hood
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
57 lines (38 loc) · 1.64 KB
/
app.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
var express = require('express'),
lessMiddleware = require('less-middleware'),
fs = require('fs'),
fsTools = require('fs-tools');
var startApp = function() {
var app = express();
app.use(express.compress());
app.use(lessMiddleware({
src: __dirname + '/public',
compress: (process.env.NODE_ENV == 'production'),
once: (process.env.NODE_ENV == 'production')
}));
app.use(express.static(__dirname + '/public'));
var port = process.env.PORT || 8000;
app.listen(port, null, null, function() {
console.log("Listening on port " + port);
});
}
// Write combined metadata file from individual location metadata files
fsTools.findSorted("public/data", /[^.]+\.metadata.json/, function(err, files) {
var metadata = {};
for (index in files) {
var metadataFilePath = files[index];
var locationName = metadataFilePath.match(/([^\/.]+)\.metadata.json/)[1];
// Exclude template file
if (locationName != "TEMPLATE") {
// Flag error and exit if metadata is not found
if (!fs.existsSync(metadataFilePath)) {
console.error("Metadata file not found for '" + locationName + "'. Aborting server start.");
process.exit(1);
}
metadata[locationName] = JSON.parse(fs.readFileSync(metadataFilePath, 'utf8'));
}
}
var metadataFileContents = "//\n// This file is auto-generated each time the application is restarted.\n//\n\nvar CITY_DATA = " + JSON.stringify(metadata) + ";";
fs.writeFileSync("public/js/data.js", metadataFileContents);
startApp();
});