Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug in middleware #177

Merged
merged 9 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading