-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
66 lines (49 loc) · 1.83 KB
/
main.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
'use strict';
const express = require('express');
const bodyParser = require('body-parser');
const hbs = require('hbs');
const path = require('path');
const appPortRaw = process.env.PORT;
const appPortParsed = parseInt(appPortRaw, 10);
// eslint-disable-next-line eqeqeq
const appPort = (appPortRaw == appPortParsed) ? appPortParsed : 4040;
const bodyJsonParser = bodyParser.json();
const bodyFormParser = bodyParser.urlencoded({ extended: true });
function startApp() {
const app = express();
const partialsPath = path.join(__dirname, 'views/partials');
app.disable('x-powered-by');
hbs.registerPartials(partialsPath);
// eslint-disable-next-line no-underscore-dangle
app.engine('hbs', hbs.__express);
/* HBS helpers */
hbs.registerHelper('json', (input) => {
return JSON.stringify(input, null, 2);
});
hbs.registerHelper('timestampToTime', (input) => {
const timeObject = new Date(Number(input));
return timeObject.toISOString();
});
app.set('view engine', 'hbs');
app.use('/public', express.static('public'));
/* Routes */
/* eslint-disable global-require */
// UI Routes
app.get('/', (req, res) => { return res.render('home', {
you: { ip: req.ip, headers: req.headers }
});
});
app.get('/readme', (req, res) => { return res.render('readme'); });
// UI Actions Routes
app.use('/actions', bodyFormParser);
app.get('/actions/lookup/auto', require('./routes/ui/actions/lookup-auto.get'));
app.get('/actions/lookup/ip', require('./routes/ui/actions/lookup-ip.get'));
app.get('/actions/lookup/domain', require('./routes/ui/actions/lookup-domain.get'));
app.get('/actions/lookup/url', require('./routes/ui/actions/lookup-url.get'));
/* eslint-enable global-require */
app.listen(appPort, () => {
console.log(`HostIdent API listening on port ${appPort}`);
});
return app;
}
startApp();