Skip to content

Commit

Permalink
run autofix
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkav committed Jan 4, 2024
1 parent 3347bca commit 93f78ba
Show file tree
Hide file tree
Showing 55 changed files with 2,312 additions and 2,322 deletions.
36 changes: 17 additions & 19 deletions app.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
{
"name": "mockbin",
"description": "Test, mock, and track HTTP requests & responses between libraries, sockets and APIs",
"repository": "https://github.com/Kong/mockbin",
"website": "http://mockbin.org/",
"success_url": "/",
"addons": [
"openredis"
],
"keywords": [
"api",
"bin",
"har",
"http",
"json",
"mock",
"mocking",
"test",
"testing"
]
"name": "mockbin",
"description": "Test, mock, and track HTTP requests & responses between libraries, sockets and APIs",
"repository": "https://github.com/Kong/mockbin",
"website": "http://mockbin.org/",
"success_url": "/",
"addons": ["openredis"],
"keywords": [
"api",
"bin",
"har",
"http",
"json",
"mock",
"mocking",
"test",
"testing"
]
}
114 changes: 62 additions & 52 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,62 @@
'use strict'

var debug = require('debug')('mockbin')
var express = require('express')
var mw = require('./middleware')
var routes = require('./routes')

module.exports = function router (options) {
var router = express.Router()

var defaults = [mw.forwarded, mw.errorHandler, mw.bodyParser, null, mw.cors, mw.poweredBy, mw.negotiateContent]

var endpoints = [
{ action: 'get', path: '/', route: routes.hello },
{ action: 'all', path: '/ip', route: routes.ips.one },
{ action: 'all', path: '/ips', route: routes.ips.all },
{ action: 'all', path: '/agent', route: routes.headers.agent },
{ action: 'all', path: '/status/:code/:reason?', route: routes.status },
{ action: 'all', path: '/headers', route: routes.headers.all },
{ action: 'all', path: '/header/:name', route: routes.headers.one },
{ action: 'all', path: '/header/:name/:value', route: routes.headers.set },
{ action: 'all', path: '/cookies', route: routes.cookies.all },
{ action: 'all', path: '/forwarded', route: routes.forwarded },
{ action: 'all', path: '/cookie/:name', route: routes.cookies.one },
{ action: 'all', path: '/cookie/:name/:value', route: routes.cookies.set },
{ action: 'all', path: '/redirect/:status_code/:count?', route: routes.redirect },
{ action: 'all', path: '/delay/:ms?', route: routes.delay },
{ action: 'all', path: '/stream/:chunks?', route: routes.stream },
{ action: 'all', path: '/har*', route: routes.har },
{ action: 'all', path: '/echo*', route: routes.echo },
{ action: 'all', path: '/request*', route: routes.request }
]

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))
})

if (options && options.redis) {
router.use('/bin', routes.bins(options.redis))
} else {
debug('no redis dsn provided, will not load bin routes')
}

// duplicate routes with gzip forced
router.use('/gzip', routes.gzip, mw.compression, Object.assign(router))

return router
}
const debug = require("debug")("mockbin");
const express = require("express");
const mw = require("./middleware");
const routes = require("./routes");

module.exports = function router(options) {
const router = express.Router();

const defaults = [
mw.forwarded,
mw.errorHandler,
mw.bodyParser,
null,
mw.cors,
mw.poweredBy,
mw.negotiateContent,
];

const endpoints = [
{ action: "get", path: "/", route: routes.hello },
{ action: "all", path: "/ip", route: routes.ips.one },
{ action: "all", path: "/ips", route: routes.ips.all },
{ action: "all", path: "/agent", route: routes.headers.agent },
{ action: "all", path: "/status/:code/:reason?", route: routes.status },
{ action: "all", path: "/headers", route: routes.headers.all },
{ action: "all", path: "/header/:name", route: routes.headers.one },
{ action: "all", path: "/header/:name/:value", route: routes.headers.set },
{ action: "all", path: "/cookies", route: routes.cookies.all },
{ action: "all", path: "/forwarded", route: routes.forwarded },
{ action: "all", path: "/cookie/:name", route: routes.cookies.one },
{ action: "all", path: "/cookie/:name/:value", route: routes.cookies.set },
{
action: "all",
path: "/redirect/:status_code/:count?",
route: routes.redirect,
},
{ action: "all", path: "/delay/:ms?", route: routes.delay },
{ action: "all", path: "/stream/:chunks?", route: routes.stream },
{ action: "all", path: "/har*", route: routes.har },
{ action: "all", path: "/echo*", route: routes.echo },
{ action: "all", path: "/request*", route: routes.request },
];

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));
});

if (options?.redis) {
router.use("/bin", routes.bins(options.redis));
} else {
debug("no redis dsn provided, will not load bin routes");
}

// duplicate routes with gzip forced
router.use("/gzip", routes.gzip, mw.compression, Object.assign(router));

return router;
};
Loading

0 comments on commit 93f78ba

Please sign in to comment.