11const debug = require ( "debug" ) ( "mockbin" ) ;
22const express = require ( "express" ) ;
33const mw = require ( "../middleware" ) ;
4- const redis = require ( "redis" ) ;
4+ const { createClient } = require ( "redis" ) ;
55const routes = require ( "./bins/" ) ;
66const URL = require ( "url" ) . URL ;
77
@@ -12,21 +12,23 @@ module.exports = function bins(dsnStr) {
1212 this . dsn = dsn ;
1313
1414 // connect to redis
15- this . client = redis . createClient ( {
15+ const client = createClient ( {
16+ legacyMode : true ,
1617 host : dsn . hostname ,
1718 port : dsn . port ,
1819 no_ready_check : true ,
1920 } ) ;
2021
2122 // Disable client's AUTH command.
22- this . client . auth = null ;
23+ client . auth = null ;
2324 if ( dsn . username ) {
24- this . client . send_command ( "AUTH" , [ dsn . username , dsn . password ] ) ;
25+ client . send_command ( "AUTH" , [ dsn . username , dsn . password ] ) ;
2526 }
2627
27- this . client . on ( "error" , ( err ) => {
28+ client . on ( "error" , ( err ) => {
2829 console . log ( "redis error:" , err ) ;
2930 } ) ;
31+ client . connect ( ) ;
3032
3133 const router = express . Router ( ) ;
3234
@@ -40,18 +42,34 @@ module.exports = function bins(dsnStr) {
4042 ] ;
4143
4244 const endpoints = [
43- { action : "get" , path : "/create" , route : routes . form . bind ( this ) } ,
44- { action : "post" , path : "/create" , route : routes . create . bind ( this ) } ,
45- { action : "get" , path : "/view/:uuid*" , route : routes . view . bind ( this ) } ,
46- { action : "get" , path : "/sample/:uuid*" , route : routes . sample . bind ( this ) } ,
47- { action : "get" , path : "/log/:uuid*" , route : routes . log . bind ( this ) } ,
45+ { action : "get" , path : "/create" , route : routes . form } ,
46+ {
47+ action : "post" ,
48+ path : "/create" ,
49+ route : routes . create ( client ) ,
50+ } ,
51+ {
52+ action : "get" ,
53+ path : "/view/:uuid*" ,
54+ route : routes . view ( client ) ,
55+ } ,
56+ {
57+ action : "get" ,
58+ path : "/sample/:uuid*" ,
59+ route : routes . sample ( client ) ,
60+ } ,
61+ {
62+ action : "get" ,
63+ path : "/log/:uuid*" ,
64+ route : routes . log ( client ) ,
65+ } ,
4866 {
4967 action : "delete" ,
5068 path : "/delete/:uuid*" ,
51- route : routes . delete . bind ( this ) ,
69+ route : routes . delete ( client ) ,
5270 } ,
53- { action : "put" , path : "/upsert/:uuid*" , route : routes . update . bind ( this ) } ,
54- { action : "all" , path : "/:uuid*" , route : routes . run . bind ( this ) } ,
71+ { action : "put" , path : "/upsert/:uuid*" , route : routes . update ( client ) } ,
72+ { action : "all" , path : "/:uuid*" , route : routes . run ( client ) } ,
5573 ] ;
5674
5775 endpoints . forEach ( ( endpoint ) => {
0 commit comments