-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
73 lines (64 loc) · 1.75 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
var harp = require('harp');
// var server = require('harp-static');
var moment = require('moment');
var outputPath = __dirname + '/www';
var port = process.env.PORT || 9000;
var express = require('express');
var app = express();
global.idify = s => {
return s
.replace(/&.*?;/g, '')
.replace(/\s+/g, '-')
.replace(/[^\w\-]/g, '')
.toLowerCase();
};
app.disable('x-powered-by');
app.use((req, res, next) => {
res.setHeader('x-powered-by', 'ffconf');
next();
});
// this line, although dirty, ensures that Harp templates
// have access to moment - which given the whole partial
// import hack doesn't work consistently across dynamic vs
// compiled, this is the cleanest solution.
global.moment = moment;
if (process.env.NODE_ENV !== 'production') {
app.use(express.static(__dirname + '/public'));
app.use(harp.mount(__dirname + '/public'));
if (module.parent) {
module.exports = app;
} else {
var server = app.listen(port, () => {
console.log(
'Listening at http://%s:%s',
server.address().address,
server.address().port
);
});
}
} else {
app.use(express.static(__dirname + '/www', { extensions: ['html'] }));
if (module.parent) {
module.exports = app;
}
harp.compile(__dirname + '/public', outputPath, errors => {
if (errors) {
console.log(JSON.stringify(errors, null, 2));
process.exit(1);
}
// server(outputPath, port);
if (!module.parent) {
console.log('Running harp-static on ' + port);
const server = app.listen(port, () => {
console.log(
'Listening at http://%s:%s',
server.address().address,
server.address().port
);
});
}
});
}
app.use((req, res) => {
res.status(404).send('404');
});