From 26ae6bd80ea15efec3fb34452acba22b4473d150 Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Sun, 24 Nov 2024 07:41:44 +1100 Subject: [PATCH] docs: update info around .handle method Closes #680 --- README.md | 33 +++++++++++++++------------------ application.ts | 5 ++--- router.ts | 4 ++-- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index eba8724..366677d 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,13 @@ import { Application } from "https://deno.land/x/oak/mod.ts"; To use from JSR, import into a module: ```ts -import { Application } from "jsr:@oak/oak@14"; +import { Application } from "jsr:@oak/oak"; +``` + +Or use the Deno CLI to add it to your project: + +``` +deno add jsr:@oak/oak ``` ### Node.js @@ -60,7 +66,7 @@ oak is available for Node.js on both [JSR](https://jsr.io/@oak/oak). To use from npm, install the package: ``` -npm i @oakserver/oak@14 +npm i @oakserver/oak ``` And then import into a module: @@ -72,7 +78,7 @@ import { Application } from "@oakserver/oak"; To use from JSR, install the package: ``` -npx jsr i @oak/oak@14 +npx jsr i @oak/oak ``` And then import into a module: @@ -95,7 +101,7 @@ oak is available for [Cloudflare Workers](https://workers.cloudflare.com/) on project: ``` -npx jsr add @oak/oak@14 +npx jsr add @oak/oak ``` And then import into a module: @@ -128,7 +134,7 @@ oak is available for Bun on [JSR](https://jsr.io/@oak/oak). To use install the package: ``` -bunx jsr i @oak/oak@14 +bunx jsr i @oak/oak ``` And then import into a module: @@ -234,19 +240,10 @@ app.use((ctx) => { ctx.response.body = "Hello World!"; }); -const listener = Deno.listen({ hostname: "localhost", port: 8000 }); - -for await (const conn of listener) { - (async () => { - const requests = Deno.serveHttp(conn); - for await (const { request, respondWith } of requests) { - const response = await app.handle(request, conn); - if (response) { - respondWith(response); - } - } - }); -} +Deno.serve(async (request, info) => { + const res = await app.handle(request, info.remoteAddr); + return res ?? Response.error(); +}); ``` An instance of application has some properties as well: diff --git a/application.ts b/application.ts index 52ae703..740c093 100644 --- a/application.ts +++ b/application.ts @@ -8,7 +8,7 @@ * # Example * * ```ts - * import { Application } from "jsr:@oak/oak@14/application"; + * import { Application } from "jsr:@oak/oak/application"; * * const app = new Application(); * app.use((ctx) => { @@ -731,8 +731,7 @@ export class Application> * is similar to `.listen()`, but opening the connection and retrieving * requests are not the responsibility of the application. If the generated * context gets set to not to respond, then the method resolves with - * `undefined`, otherwise it resolves with a request that is compatible with - * `std/http/server`. */ + * `undefined`, otherwise it resolves with a standard {@linkcode Response}. */ handle: HandleMethod = (async ( request: Request, secureOrAddr: NetAddr | boolean | undefined, diff --git a/router.ts b/router.ts index 81f7ee0..d988323 100644 --- a/router.ts +++ b/router.ts @@ -7,8 +7,8 @@ * # Example * * ```ts - * import { Application } from "jsr:@oak/oak@14/application"; - * import { Router } from "jsr:@oak/oak@14/router"; + * import { Application } from "jsr:@oak/oak/application"; + * import { Router } from "jsr:@oak/oak/router"; * * const app = new Application(); * const router = new Router();