-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored working with latest node (#118)
* Refactored working with latest node * Resolved formatting issue with * Resolved defect with content type * bump and refresh lock --------- Co-authored-by: jackkav <[email protected]>
- Loading branch information
1 parent
a31208c
commit babb88d
Showing
20 changed files
with
2,590 additions
and
2,465 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"asi": true, | ||
"node": true | ||
"node": true, | ||
"esversion": 8 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
services: | ||
app: | ||
build: . | ||
environment: | ||
REALM: prod | ||
REDIS_URL: "//redis:6379" | ||
links: | ||
- redis | ||
ports: | ||
- "8080:8080" | ||
|
||
redis: | ||
image: redis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,65 @@ | ||
'use strict' | ||
|
||
var debug = require('debug-log')('mockbin') | ||
var express = require('express') | ||
var mw = require('../middleware') | ||
var redis = require('redis') | ||
var routes = require('./bins/') | ||
var URL = require('url').URL | ||
var debug = require("debug")("mockbin"); | ||
var express = require("express"); | ||
var mw = require("../middleware"); | ||
var redis = require("redis"); | ||
var routes = require("./bins/"); | ||
var URL = require("url").URL; | ||
|
||
module.exports = function bins(dsnStr) { | ||
// parse redis dsn | ||
var dsn = new URL(dsnStr) | ||
|
||
// connect to redis | ||
this.client = redis.createClient(dsn.port, dsn.hostname, { | ||
auth_pass: dsn.auth ? dsn.auth.split(':').pop() : false | ||
}) | ||
|
||
this.client.on('error', function (err) { | ||
debug('redis error:', err) | ||
}) | ||
|
||
var router = express.Router() | ||
|
||
var defaults = [mw.forwarded, mw.errorHandler, mw.bodyParser, null, mw.cors, mw.negotiateContent] | ||
|
||
var endpoints = [ | ||
{ action: 'get', path: '/create', route: routes.form.bind(this) }, | ||
{ action: 'post', path: '/create', route: routes.create.bind(this) }, | ||
{ action: 'get', path: '/:uuid/view', route: routes.view.bind(this) }, | ||
{ action: 'get', path: '/:uuid/sample', route: routes.sample.bind(this) }, | ||
{ action: 'get', path: '/:uuid/log', route: routes.log.bind(this) }, | ||
{ action: 'delete', path: '/:uuid/delete', route: routes.delete.bind(this) }, | ||
{ action: 'put', path: '/:uuid', route: routes.update.bind(this) }, | ||
{ action: 'all', path: '/:uuid*', route: routes.run.bind(this) } | ||
] | ||
|
||
endpoints.forEach(function (endpoint) { | ||
// add route to middleware | ||
defaults.splice(3, 1, endpoint.route) | ||
|
||
// assign router to action at path | ||
router[endpoint.action].apply(router, [endpoint.path].concat(defaults)) | ||
}) | ||
|
||
return router | ||
} | ||
// parse redis dsn | ||
var dsn = new URL(dsnStr); | ||
|
||
this.dsn = dsn; | ||
|
||
// connect to redis | ||
this.client = redis.createClient( | ||
{ | ||
host: dsn.hostname, | ||
port: dsn.port, | ||
no_ready_check: true | ||
}) | ||
|
||
// Disable client's AUTH command. | ||
this.client.auth = null | ||
this.client.send_command('AUTH', [dsn.username, dsn.password]) | ||
|
||
this.client.on("error", (err) => { | ||
debug("redis error:", err); | ||
}); | ||
|
||
var router = express.Router(); | ||
|
||
var defaults = [ | ||
mw.forwarded, | ||
mw.errorHandler, | ||
mw.bodyParser, | ||
null, | ||
mw.cors, | ||
mw.negotiateContent, | ||
]; | ||
|
||
var endpoints = [ | ||
{ action: "get", path: "/create", route: routes.form.bind(this) }, | ||
{ action: "post", path: "/create", route: routes.create.bind(this) }, | ||
{ action: "get", path: "/:uuid/view", route: routes.view.bind(this) }, | ||
{ action: "get", path: "/:uuid/sample", route: routes.sample.bind(this) }, | ||
{ action: "get", path: "/:uuid/log", route: routes.log.bind(this) }, | ||
{ | ||
action: "delete", | ||
path: "/:uuid/delete", | ||
route: routes.delete.bind(this), | ||
}, | ||
{ action: "put", path: "/:uuid", route: routes.update.bind(this) }, | ||
{ action: "all", path: "/:uuid*", route: routes.run.bind(this) }, | ||
]; | ||
|
||
endpoints.forEach((endpoint) => { | ||
// add route to middleware | ||
defaults.splice(3, 1, endpoint.route); | ||
|
||
// assign router to action at path | ||
router[endpoint.action].apply(router, [endpoint.path].concat(defaults)); | ||
}); | ||
|
||
return router; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.