Skip to content

Commit

Permalink
Merge pull request #177 from Kong/fix-middleware-bug
Browse files Browse the repository at this point in the history
fix bug in middleware
  • Loading branch information
jackkav authored Jul 1, 2024
2 parents e32332a + c8406a7 commit d8cd876
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Insomnia Mockbin is maintained by [Kong](https://github.com/Kong), who also main
- [Running with Docker Compose](#running-with-docker-compose)
- [Documentation](#documentation)
- [API Docs](#api-docs)
- [Releasing](#releasing)
- [Software Bill of materials](#software-bill-of-materials)
- [Verify a container image signature](#verify-a-container-image-signature)
- [Verify a container image provenance](#verify-a-container-image-provenance)
Expand Down Expand Up @@ -77,6 +78,16 @@ docker compose up

Read the full API documentation, please review the [API Docs](https://github.com/Kong/mockbin/tree/master/docs).

## Releasing

Run the following command and push the newly created commit into your PR.
This will bump commit and tag, you will need to push this to the remote, which trigger the release action upon merging the PR.

```sh
npm version patch
git push origin tag <tag_name>
```

### Software Bill of materials

Kong Insomnia Mockbin produces SBOMs for the below categories:
Expand Down
23 changes: 11 additions & 12 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ const routes = require("./routes");
module.exports = function (options) {
const router = express.Router();

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

const endpoints = [
{ action: "get", path: "/", route: routes.hello },
{ action: "all", path: "/ip", route: routes.ips.one },
Expand All @@ -38,11 +30,18 @@ module.exports = function (options) {
];

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));
router[endpoint.action].apply(
router,
[endpoint.path].concat([
mw.errorHandler,
mw.bodyParser,
endpoint.route,
mw.cors,
mw.poweredBy,
mw.negotiateContent,
]),
);
});

if (options?.redis) {
Expand Down
22 changes: 10 additions & 12 deletions lib/routes/bins.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ module.exports = function bins(dsnStr) {

const router = express.Router();

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

const endpoints = [
{ action: "get", path: "/create", route: routes.form },
{
Expand Down Expand Up @@ -69,11 +61,17 @@ module.exports = function bins(dsnStr) {
];

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));
router[endpoint.action].apply(
router,
[endpoint.path].concat([
mw.errorHandler,
mw.bodyParser,
endpoint.route,
mw.cors,
mw.negotiateContent,
]),
);
});

return router;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.0.1",
"version": "2.0.2",
"name": "mockbin",
"description": "Test, mock, and track HTTP requests & responses between libraries, sockets and APIs",
"author": "Kong (https://www.konghq.com/)",
Expand Down

0 comments on commit d8cd876

Please sign in to comment.