Compare View
Commits (2)
Changes
Showing 2 changed files Inline Diff
logger-circular-buffer-web.js
1 | "use strict"; | 1 | "use strict"; |
2 | 2 | ||
3 | const http = require('http'); | 3 | const http = require('http'); |
4 | const auth = require('basic-auth'); | 4 | const auth = require('basic-auth'); |
5 | 5 | ||
6 | const config = require('./config'); | 6 | const config = require('./config'); |
7 | const logger = require('./logger'); | 7 | const logger = require('./logger'); |
8 | 8 | ||
9 | function listen(options) { | 9 | function listen(options) { |
10 | if (options && options.port && options.username && options.password) { | 10 | if (options && options.port && options.username && options.password) { |
11 | 11 | ||
12 | http.createServer(function(req, res) { | 12 | http.createServer(function(req, res) { |
13 | var credentials = auth(req); | 13 | var credentials = auth(req); |
14 | 14 | ||
15 | if (!credentials && credentials.name != options.username && credentials.pass != options.password) { | 15 | if (!credentials && credentials.name != options.username && credentials.pass != options.password) { |
16 | res.statusCode = 401; | 16 | res.statusCode = 401; |
17 | res.setHeader('WWW-Authenticate', 'Basic realm="example"'); | 17 | res.setHeader('WWW-Authenticate', 'Basic realm="example"'); |
18 | res.end('Access denied'); | 18 | res.end('Access denied'); |
19 | } | 19 | } |
20 | else { | 20 | else { |
21 | 21 | ||
22 | logger.query({json: true, order: desc}, function(err, results) { | 22 | logger.query({json: true, order: desc}, function(err, results) { |
23 | if (err) { | 23 | if (err) { |
24 | res.end('INVALID LOGGER'); | 24 | res.end('INVALID LOGGER'); |
25 | } | 25 | } |
26 | else { | 26 | else { |
27 | res.writeHead(200, { 'Content-Type': 'application/json' }); | 27 | res.writeHead(200, { 'Content-Type': 'application/json' }); |
28 | res.end(JSON.stringify(results)); | 28 | res.end(JSON.stringify(results)); |
29 | } | 29 | } |
30 | }); | 30 | }); |
31 | } | 31 | } |
32 | }).listen(options.port); | 32 | }).listen(options.port); |
33 | 33 | ||
34 | logger.verbose('Logger circular buffer http server listen on port ' + options.port); | 34 | logger.verbose('Logger circular buffer http server listen on port ' + options.port); |
35 | } | 35 | } |
36 | else { | ||
37 | logger.verbose('Circular buffer logger http server viewer is not configured. Please set options.port, options.username, options.password'); | ||
38 | } | ||
39 | |||
36 | else { | 40 | } |
41 | |||
42 | exports.listen = listen; | ||
37 | logger.verbose('Circular buffer logger http server viewer is not configured. Please set options.port, options.username, options.password'); | 43 |
package.json
1 | { | 1 | { |
2 | "name": "komodo-sdk", | 2 | "name": "komodo-sdk", |
3 | "version": "1.6.9", | 3 | "version": "1.6.10", |
4 | "description": "SDK for Komodo", | 4 | "description": "SDK for Komodo", |
5 | "main": "index.js", | 5 | "main": "index.js", |
6 | "scripts": { | 6 | "scripts": { |
7 | "test": "mocha", | 7 | "test": "mocha", |
8 | "postversion": "git push && git push --tags" | 8 | "postversion": "git push && git push --tags" |
9 | }, | 9 | }, |
10 | "repository": { | 10 | "repository": { |
11 | "type": "git", | 11 | "type": "git", |
12 | "url": "git@gitlab.kodesumber.com:komodo/komodo-sdk.git" | 12 | "url": "git@gitlab.kodesumber.com:komodo/komodo-sdk.git" |
13 | }, | 13 | }, |
14 | "keywords": [ | 14 | "keywords": [ |
15 | "ppob", | 15 | "ppob", |
16 | "payment", | 16 | "payment", |
17 | "komodo" | 17 | "komodo" |
18 | ], | 18 | ], |
19 | "author": "Adhidarma Hadiwinoto <gua@adhisimon.org>", | 19 | "author": "Adhidarma Hadiwinoto <gua@adhisimon.org>", |
20 | "license": "ISC", | 20 | "license": "ISC", |
21 | "dependencies": { | 21 | "dependencies": { |
22 | "basic-auth": "^2.0.0", | 22 | "basic-auth": "^2.0.0", |
23 | "lru-cache": "^4.1.1", | 23 | "lru-cache": "^4.1.1", |
24 | "request": "^2.81.0", | 24 | "request": "^2.81.0", |
25 | "strftime": "^0.10.0", | 25 | "strftime": "^0.10.0", |
26 | "winston": "^2.3.1", | 26 | "winston": "^2.3.1", |
27 | "winston-circular-buffer": "^1.0.0", | 27 | "winston-circular-buffer": "^1.0.0", |
28 | "winston-daily-rotate-file": "^1.4.6" | 28 | "winston-daily-rotate-file": "^1.4.6" |
29 | } | 29 | } |
30 | } | 30 | } |
31 | 31 |