forked from LePetitBloc/bitcoind-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createServer.js
33 lines (24 loc) · 917 Bytes
/
createServer.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
const { resolve } = require('path');
const express = require('express');
const serveStatic = require('serve-static');
const helmet = require('helmet');
const compression = require('compression');
const createServer = metricsHandler => {
const port = 9439;
const app = express();
app.use(compression());
app.use(helmet());
app.use(serveStatic(resolve('./public')));
app.get('/metrics', metricsHandler);
app.use((req, res) => {
console.warn(`Requested URL ${req.url} resulted in a 404 not found error.`);
res.status(404).send('# This metric doesn\'t exists\n');
});
app.listen(port, () => console.info(`Wallet exporter started on http://localhost:${port}`));
process.on('SIGINT', () => {
console.info(`Wallet exporter gracefully shut down from SIGINT (Ctrl-C)`);
process.exit(0);
});
return app;
};
module.exports = createServer;