Skip to content

Commit

Permalink
feat: change serve function
Browse files Browse the repository at this point in the history
  • Loading branch information
antho-bunny committed Aug 29, 2024
1 parent 0625f1a commit 49b0fa1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/polite-trees-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bunny.net/edgescript-sdk": minor
---

serve function should have the handler as first arg
2 changes: 1 addition & 1 deletion example/deno-simple-http-page/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function sleep(ms: number): Promise<void> {
}

console.log("Starting server...");
BunnySDK.net.http.serve({ port: 8080, hostname: '127.0.0.1' }, async (req) => {
BunnySDK.net.http.serve(async (req) => {
console.log(`[INFO]: ${req.method} - ${req.url}`);
await sleep(1);
return new Response("blbl");
Expand Down
2 changes: 1 addition & 1 deletion example/simple-http-page/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function sleep(ms: number): Promise<void> {

console.log("Starting server...");

BunnySDK.net.http.serve({ port: 8080, hostname: '127.0.0.1' }, async (req) => {
BunnySDK.net.http.serve(async (req) => {
console.log(`[INFO]: ${req.method} - ${req.url}`);
await sleep(1);
return new Response("blbl");
Expand Down
6 changes: 3 additions & 3 deletions libs/bunny-sdk/src/net/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ type ServeHandler = {} & unknown;
/**
* Serves HTTP requests on the given [TcpListener]
*/
function serve(listener: { port: number; hostname: string; }, handler: ServerHandler): ServeHandler;
function serve(listener: TcpListener, handler: ServerHandler): ServeHandler;
function serve(listener: TcpListener | { port: number; hostname: string; }, handler: ServerHandler): ServeHandler {
function serve(handler: ServerHandler, listener: { port: number; hostname: string; }): ServeHandler;
function serve(handler: ServerHandler, listener: TcpListener): ServeHandler;
function serve(handler: ServerHandler, listener?: TcpListener | { port: number; hostname: string; },): ServeHandler {
const platform = internal_getPlatform();

const listenerUnion = Tcp.isTcpListener(listener) ? listener : Tcp.unstable_new();
Expand Down

0 comments on commit 49b0fa1

Please sign in to comment.