Commit 26921e0c2d2c08951140e389d305f3f7babe347e
1 parent
5a00ec06f9
Exists in
master
404 on favicon request
Showing 1 changed file with 5 additions and 0 deletions Inline Diff
lib/http-command-server/index.js
1 | 'use strict'; | 1 | 'use strict'; |
2 | 2 | ||
3 | const express = require('express'); | 3 | const express = require('express'); |
4 | 4 | ||
5 | const config = require('komodo-sdk/config'); | 5 | const config = require('komodo-sdk/config'); |
6 | const logger = require('komodo-sdk/logger'); | 6 | const logger = require('komodo-sdk/logger'); |
7 | 7 | ||
8 | const routerInfo = require('./router-info'); | 8 | const routerInfo = require('./router-info'); |
9 | const routerSMS = require('./router-sms'); | 9 | const routerSMS = require('./router-sms'); |
10 | 10 | ||
11 | const app = express(); | 11 | const app = express(); |
12 | 12 | ||
13 | function middlewareCustomLog(req, res, next) { | 13 | function middlewareCustomLog(req, res, next) { |
14 | if (req.url.indexOf('/favicon.ico') === 0) { | ||
15 | res.sendStatus(404); | ||
16 | return; | ||
17 | } | ||
18 | |||
14 | logger.info('Incoming request on HTTP command server', { ip: req.ip, url: req.url }); | 19 | logger.info('Incoming request on HTTP command server', { ip: req.ip, url: req.url }); |
15 | next(); | 20 | next(); |
16 | } | 21 | } |
17 | 22 | ||
18 | function middlewareCheckApikey(req, res, next) { | 23 | function middlewareCheckApikey(req, res, next) { |
19 | if (!req.query.apikey || (req.query.apikey !== config.http_command_server.apikey)) { | 24 | if (!req.query.apikey || (req.query.apikey !== config.http_command_server.apikey)) { |
20 | res.json({ | 25 | res.json({ |
21 | status: 'NOT-OK', | 26 | status: 'NOT-OK', |
22 | error: 'INVALID_APIKEY', | 27 | error: 'INVALID_APIKEY', |
23 | message: 'Invalid apikey', | 28 | message: 'Invalid apikey', |
24 | }); | 29 | }); |
25 | } else { | 30 | } else { |
26 | next(); | 31 | next(); |
27 | } | 32 | } |
28 | } | 33 | } |
29 | 34 | ||
30 | app.use(middlewareCustomLog); | 35 | app.use(middlewareCustomLog); |
31 | app.use(middlewareCheckApikey); | 36 | app.use(middlewareCheckApikey); |
32 | 37 | ||
33 | app.use('/info', routerInfo); | 38 | app.use('/info', routerInfo); |
34 | app.use('/sms', routerSMS); | 39 | app.use('/sms', routerSMS); |
35 | 40 | ||
36 | 41 | ||
37 | app.listen(config.http_command_server.listen_port, () => { | 42 | app.listen(config.http_command_server.listen_port, () => { |
38 | logger.info(`HTTP command server listeing on port ${config.http_command_server.listen_port}`); | 43 | logger.info(`HTTP command server listeing on port ${config.http_command_server.listen_port}`); |
39 | }); | 44 | }); |
40 | 45 |