-
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.
* add action * move to workflow * fix yml
- Loading branch information
Showing
5 changed files
with
101 additions
and
312 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: Test | ||
on: push | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 18 | ||
- run: npm ci | ||
- run: npm test |
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,65 +1,65 @@ | ||
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; | ||
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); | ||
module.exports = function bins (dsnStr) { | ||
// parse redis dsn | ||
var dsn = new URL(dsnStr) | ||
|
||
this.dsn = dsn; | ||
this.dsn = dsn | ||
|
||
// connect to redis | ||
this.client = redis.createClient( | ||
{ | ||
host: dsn.hostname, | ||
port: dsn.port, | ||
no_ready_check: true | ||
}) | ||
// 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]) | ||
// 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); | ||
}); | ||
this.client.on('error', (err) => { | ||
debug('redis error:', err) | ||
}) | ||
|
||
var router = express.Router(); | ||
var router = express.Router() | ||
|
||
var defaults = [ | ||
mw.forwarded, | ||
mw.errorHandler, | ||
mw.bodyParser, | ||
null, | ||
mw.cors, | ||
mw.negotiateContent, | ||
]; | ||
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) }, | ||
]; | ||
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); | ||
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)); | ||
}); | ||
// assign router to action at path | ||
router[endpoint.action].apply(router, [endpoint.path].concat(defaults)) | ||
}) | ||
|
||
return router; | ||
}; | ||
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
Oops, something went wrong.