Compare View
Commits (3)
Changes
Showing 4 changed files Inline Diff
.gitignore
1 | /node_modules/ | 1 | /node_modules/ |
2 | /logs/ | ||
2 | /logs/ | 3 |
api-server/index.js
File was created | 1 | "use strict"; | |
2 | |||
3 | /** | ||
4 | * API Server | ||
5 | * | ||
6 | * @todo make it work | ||
7 | */ | ||
8 | |||
9 | const express = require('express'); | ||
10 | |||
11 | const config = require('../config'); | ||
12 | const logger = require('../logger'); | ||
13 | const matrix = require('../matrix'); | ||
14 | const routerConfig = require('./router-config'); | ||
15 | |||
16 | const app = express(); | ||
17 | |||
18 | function isConfigured() { | ||
19 | return Boolean(config && config.apiserver && config.apiserver.apikey && config.apiserver.port); | ||
20 | } | ||
21 | |||
22 | function isValidApiKey(apikey) { | ||
23 | return isConfigured() && (config.apiserver.apikey === apikey); | ||
24 | } | ||
25 | |||
26 | function needValidApikey(req, res, next) { | ||
27 | if (isValidApikey(req.params.apikey)) { | ||
28 | next(); | ||
29 | } | ||
30 | else { | ||
31 | res.end('INVALID_APIKEY'); | ||
32 | } | ||
33 | } | ||
34 | |||
35 | isConfigured() && app.listen(config.push_server.advice.port, function () { | ||
36 | logger.info('API-SERVER listening', {port: config.push_server.advice.port}); | ||
37 | }); | ||
38 | |||
39 | |||
40 | app.use('/apikey/:apikey', needValidApikey); | ||
41 | app.use('/apikey/:apikey/config', routerConfig); | ||
1 | "use strict"; | 42 |
api-server/router-config.js
File was created | 1 | "use strict"; | |
2 | |||
3 | const express = require('express'); | ||
4 | |||
5 | const config = require('../config'); | ||
6 | const logger = require('../logger'); | ||
7 | const matrix = require('../matrix'); | ||
8 | |||
9 | const router = express.Router(); | ||
10 | module.exports = router; | ||
11 | |||
12 | function getJsonConfig(req, res, next) { | ||
13 | res.json(config); | ||
14 | } | ||
15 | |||
16 | function getConfigElement(req, res, next) { | ||
17 | const paths = req.path.split('.'); | ||
18 | res.json(paths); | ||
19 | } | ||
20 | |||
21 | router.get('/', getJsonConfig); | ||
22 | router.post('/', getJsonConfig); | ||
23 | router.use('/get', getConfigElement); | ||
1 | "use strict"; | 24 |
package.json
1 | { | 1 | { |
2 | "name": "komodo-sdk", | 2 | "name": "komodo-sdk", |
3 | "version": "1.23.7", | 3 | "version": "1.24.0", |
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 | "body-parser": "^1.18.2", | 23 | "body-parser": "^1.18.2", |
24 | "express": "^4.16.3", | 24 | "express": "^4.16.3", |
25 | "express-session": "^1.15.6", | 25 | "express-session": "^1.15.6", |
26 | "lru-cache": "^4.1.1", | 26 | "lru-cache": "^4.1.1", |
27 | "macaddress": "^0.2.8", | 27 | "macaddress": "^0.2.8", |
28 | "moment": "^2.19.1", | 28 | "moment": "^2.19.1", |
29 | "node-machine-id": "^1.1.10", | 29 | "node-machine-id": "^1.1.10", |
30 | "node-natural-sort": "^0.8.6", | 30 | "node-natural-sort": "^0.8.6", |
31 | "numeral": "^2.0.6", | 31 | "numeral": "^2.0.6", |
32 | "nunjucks": "^3.0.1", | 32 | "nunjucks": "^3.0.1", |
33 | "redis": "^2.8.0", | 33 | "redis": "^2.8.0", |
34 | "request": "^2.81.0", | 34 | "request": "^2.81.0", |
35 | "sha1": "^1.1.1", | 35 | "sha1": "^1.1.1", |
36 | "simple-git": "^1.80.1", | 36 | "simple-git": "^1.80.1", |
37 | "strftime": "^0.10.0", | 37 | "strftime": "^0.10.0", |
38 | "uniqid": "^4.1.1", | 38 | "uniqid": "^4.1.1", |
39 | "uuid": "^3.1.0", | 39 | "uuid": "^3.1.0", |
40 | "winston": "^2.3.1", | 40 | "winston": "^2.3.1", |
41 | "winston-circular-buffer": "^1.0.0", | 41 | "winston-circular-buffer": "^1.0.0", |
42 | "winston-daily-rotate-file": "^1.4.6" | 42 | "winston-daily-rotate-file": "^1.4.6" |
43 | } | 43 | } |
44 | } | 44 | } |
45 | 45 |