-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support declarative style fetch handler (#400)
* feat: support declarative style fetch handler * chore: add a simple integration test for declarative style fetch handler
- Loading branch information
1 parent
53061f6
commit 5d4a9b4
Showing
6 changed files
with
60 additions
and
0 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,5 @@ | ||
export default { | ||
async fetch(_req: Request) { | ||
return new Response("meow"); | ||
} | ||
} |
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,22 @@ | ||
import { primordials } from "ext:core/mod.js"; | ||
|
||
const { ObjectHasOwn } = primordials; | ||
|
||
function registerDeclarativeServer(exports) { | ||
if (ObjectHasOwn(exports, "fetch")) { | ||
if (typeof exports.fetch !== "function") { | ||
throw new TypeError( | ||
"Invalid type for fetch: must be a function with a single or no parameter", | ||
); | ||
} | ||
Deno.serve({ | ||
handler: (req) => { | ||
return exports.fetch(req); | ||
}, | ||
}); | ||
} | ||
} | ||
|
||
export { | ||
registerDeclarativeServer | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default { | ||
async fetch(_req: Request) { | ||
return new Response("Hello, world"); | ||
} | ||
} |