Skip to content

Commit

Permalink
Merge pull request #16 from rikilele/develop
Browse files Browse the repository at this point in the history
v0.3.0-rc
  • Loading branch information
rikilele authored Jul 8, 2021
2 parents ba7712e + 60eabe0 commit 2e7ec9b
Show file tree
Hide file tree
Showing 15 changed files with 555 additions and 307 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ name: ci

on:
push:
branches: [main]
branches:
- main
- develop
pull_request:
branches: [main]
branches:
- main
- develop

jobs:
test:
Expand Down
68 changes: 0 additions & 68 deletions KyukoResponse.ts

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ It aims to provide a similar experience to developing API servers with
Deployed at https://kyuko.deno.dev

```ts
import { Kyuko } from "https://deno.land/x/[email protected]";
import { Kyuko } from "https://deno.land/x/[email protected]/mod.ts";

const app = new Kyuko();

Expand Down
18 changes: 18 additions & 0 deletions examples/errorHandling.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2021 Riki Singh Khorana. All rights reserved. MIT license.

import { Kyuko } from "../mod.ts";

const app = new Kyuko();

/**
* This will handle the error thrown.
*/
app.error((err, _req, res) => {
res.send(err.message);
});

app.get("/", (_req, _res) => {
throw new Error("An intentional error occurred!");
});

app.listen();
12 changes: 10 additions & 2 deletions examples/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
// Copyright 2021 Riki Singh Khorana. All rights reserved. MIT license.

import { Kyuko } from "../mod.ts";
import { decodeParams } from "../middleware/decodeParams.ts";
import { json, KyukoRequestWithJson } from "../middleware/json.ts";

const app = new Kyuko();

// Uses the `json` middleware
app.use(json);
app.use(decodeParams());
app.use(json());

/**
* Try accessing encoded url paths such as "/Alice%20%26%20Bob".
*/
app.get("/:name", (req, res) => {
res.send(`Hello ${req.params.name}!`);
});

/**
* Responds with a pretty version of the JSON request body.
Expand Down
220 changes: 0 additions & 220 deletions kyuko.ts

This file was deleted.

13 changes: 13 additions & 0 deletions middleware/decodeParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { KyukoMiddleware, KyukoRequest } from "../mod.ts";

/**
* Returns a `KyukoMiddleware` that decodes the values of `req.params`.
*/
export function decodeParams(): KyukoMiddleware {
return function (req: KyukoRequest) {
Object.keys(req.params).forEach((param) => {
const encoded = req.params[param];
req.params[param] = decodeURIComponent(encoded);
});
};
}
Loading

0 comments on commit 2e7ec9b

Please sign in to comment.