-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix some tests, implement a val-town like pattern, better error surfa…
…cing
- Loading branch information
Showing
7 changed files
with
163 additions
and
15 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
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 |
---|---|---|
|
@@ -30,7 +30,6 @@ | |
"vitest": "^1.5.0" | ||
}, | ||
"dependencies": { | ||
"got": "^14.2.1", | ||
"http2-wrapper": "^2.2.1" | ||
"got": "^14.2.1" | ||
} | ||
} |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export { newDenoHTTPWorker } from "./DenoHTTPWorker.js"; | ||
export type { DenoHTTPWorker } from "./DenoHTTPWorker.js"; |
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,12 @@ | ||
export default async function (req: Request): Promise<Response> { | ||
let headers: { [key: string]: string } = {}; | ||
for (let [key, value] of req.headers.entries()) { | ||
headers[key] = value; | ||
} | ||
return Response.json({ | ||
url: req.url, | ||
headers: headers, | ||
body: await req.text(), | ||
method: req.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
let initialized = false; | ||
let initializing = false; | ||
let handler: (req: Request) => Promise<Response> | Response; | ||
|
||
let pendingRequests: any[] = []; | ||
export default async function (req: Request): Promise<Response> { | ||
if (initializing) { | ||
return new Promise((resolve, reject) => { | ||
pendingRequests.push({ req, resolve, reject }); | ||
}); | ||
} | ||
if (!initialized) { | ||
initializing = true; | ||
try { | ||
let source = await req.text(); | ||
if (!source) { | ||
return new Response("No source provided", { status: 400 }); | ||
} | ||
handler = (await import(source)).default; | ||
initialized = true; | ||
initializing = false; | ||
for (const { req, resolve } of pendingRequests) { | ||
resolve(handler(req)); | ||
} | ||
} catch (e: any) { | ||
return new Response(e, { status: 500 }); | ||
} | ||
return new Response(""); | ||
} | ||
return handler(req); | ||
} |