-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for http method exports in route modules.
- Loading branch information
Showing
10 changed files
with
151 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), | ||
and this project adheres to | ||
[Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [0.7.0] | ||
|
||
### Added | ||
|
||
- Support for modules that export http method functions rather than a default | ||
handler, when generating a routes module. | ||
- `lazy` supports module transformation after loading (to allow dynamic loading | ||
of http method modules). | ||
|
||
### Fixed | ||
|
||
- `generate_routes.ts` example to enable `jsr` imports. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { | ||
assertEquals, | ||
assertOk, | ||
assertStatus, | ||
STATUS_CODE, | ||
} from "./_test_deps.ts"; | ||
|
||
Deno.test("generated routes.ts", async (t) => { | ||
await using _server = (await import("./generated_routes.ts")).default; | ||
|
||
await t.step("GET /", async () => { | ||
const response = await fetch("/"); | ||
|
||
assertOk(response); | ||
assertEquals(await response.text(), "This is the index page"); | ||
}); | ||
|
||
await t.step("GET /user/bob", async () => { | ||
const response = await fetch("/user/bob"); | ||
|
||
assertOk(response); | ||
assertEquals(await response.text(), "Hello bob"); | ||
}); | ||
|
||
await t.step("GET /methods", async () => { | ||
const response = await fetch("/methods"); | ||
|
||
assertOk(response); | ||
assertEquals(await response.text(), "GET method"); | ||
}); | ||
|
||
await t.step("PUT /methods", async () => { | ||
const response = await fetch("/methods", { method: "PUT" }); | ||
|
||
assertOk(response); | ||
assertEquals(await response.text(), "PUT method"); | ||
}); | ||
|
||
await t.step("POST /methods", async () => { | ||
const response = await fetch("/methods", { method: "POST" }); | ||
|
||
assertOk(response); | ||
assertEquals(await response.text(), "POST method"); | ||
}); | ||
|
||
await t.step("DELETE /methods (405)", async () => { | ||
const response = await fetch("/methods", { method: "DELETE" }); | ||
|
||
assertStatus(response, STATUS_CODE.MethodNotAllowed); | ||
await response.body?.cancel(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
// IMPORTANT: This file has been automatically generated, DO NOT edit by hand. | ||
|
||
import { byMethod } from "@http/fns/by_method"; | ||
import { lazy } from "@http/fns/lazy"; | ||
import { byPattern } from "@http/fns/by_pattern"; | ||
import { cascade } from "@http/fns/cascade"; | ||
import { lazy } from "@http/fns/lazy"; | ||
|
||
export default cascade( | ||
byPattern("/user/:name", lazy(() => import("./routes/user/[name].ts"))), | ||
byPattern( | ||
"/methods", | ||
lazy(async () => byMethod(await import("./routes/methods.ts"))), | ||
), | ||
byPattern("/", lazy(() => import("./routes/index.ts"))), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { ok } from "@http/fns/response/ok"; | ||
|
||
export function GET(_req: Request) { | ||
return ok(`GET method`); | ||
} | ||
|
||
export function PUT(_req: Request) { | ||
return ok(`PUT method`); | ||
} | ||
|
||
export function POST(_req: Request) { | ||
return ok(`POST method`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters