-
Notifications
You must be signed in to change notification settings - Fork 30
/
app.js
89 lines (74 loc) · 2.13 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
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
89
const express = require('express');
const cachifyStatic = require('connect-cachify-static');
const gzip = require('connect-gzip-static');
const http = require('node:http');
const path = require('node:path');
const loaders = require('./lib/loaders');
const plugins = require('./lib/plugins');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const errorHandler = require('errorhandler');
const app = module.exports = express();
if (!process.env.SITE_URL) {
process.env.SITE_URL = app.get('env') === 'production' ?
'https://liftie.info' :
'http://localhost:3000';
}
const root = path.join(__dirname, 'public');
const {
SITE_URL: siteUrl,
LIFTIE_STATIC_HOST: staticHost = ''
} = process.env;
const cachify = cachifyStatic(root);
Object.assign(app.locals, {
min: '.min',
decorateAbout() {},
siteUrl,
staticHost,
serviceWorker: true,
og: {
image: `${staticHost || siteUrl}/img/snowflake-512.png`
}
});
app.set('port', process.env.PORT || 3000);
app.set('views', `${__dirname}/views`);
app.engine('jade', require('@pirxpilot/jade-core').__express);
app.set('view engine', 'jade');
app.use(logger('dev'));
app.use(cookieParser());
app.use(cachify);
app.use((_req, res, next) => {
cachify.helpers().then(fns => {
res.locals.cachify = fns.cachify;
next();
});
});
app.use(gzip(root));
if (app.get('env') === 'development') {
app.locals.min = '';
app.use(errorHandler());
}
app.loaders = loaders;
app.loaders.register(require('./lib/loader'));
app.plugins = plugins;
app.plugins.register('lifts', require('./lib/lifts'));
app.plugins.register('opening', require('./lib/opening'));
app.plugins.register('weather', require('./lib/weather'));
app.plugins.register('webcams', require('./lib/webcams'));
app.data = require('./lib/routes/data')();
require('./lib/routes')(app);
app.run = function run() {
app.data.init(err => {
if (err) {
console.error(err);
process.exit(1);
return;
}
http.createServer(app).listen(app.get('port'), () => {
console.log(`Running on: http://localhost:${app.get('port')}`);
});
});
};
if (!module.parent) {
app.run();
}