-
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.
Remove all the deno flags options and replace with simpler implementa…
…tion
- Loading branch information
Showing
6 changed files
with
123 additions
and
315 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 |
---|---|---|
|
@@ -35,5 +35,5 @@ jobs: | |
CI: true | ||
# - name: deno test | ||
# run: | | ||
# cd deno-guest | ||
# cd deno-bootstrap | ||
# deno test |
File renamed without changes.
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,51 @@ | ||
const scriptType = Deno.args[0]; | ||
const script = Deno.args[1]; | ||
|
||
const importURL = | ||
scriptType == "import" | ||
? script | ||
: "data:text/tsx," + encodeURIComponent(script); | ||
|
||
const server = Deno.listen({ | ||
hostname: "0.0.0.0", | ||
port: 0, | ||
}); | ||
|
||
const addr = server.addr as Deno.NetAddr; | ||
|
||
console.log(`deno-listening-port ${addr.port.toString().padStart(5, " ")} `); | ||
|
||
// Now that we're listening, start executing user-provided code. We could | ||
// import while starting the server for a small performance improvement, | ||
// but it would complicate reading the port from the Deno logs. | ||
const handler = await import(importURL); | ||
if (!handler.default) { | ||
throw new Error("No default export found in script."); | ||
} | ||
if (typeof handler.default !== "function") { | ||
throw new Error("Default export is not a function."); | ||
} | ||
|
||
const conn = await server.accept(); | ||
(async () => { | ||
// Reject all additional connections. | ||
for await (const conn of server) { | ||
conn.close(); | ||
} | ||
})(); | ||
const httpConn = Deno.serveHttp(conn); | ||
for await (const requestEvent of httpConn) { | ||
(async () => { | ||
let req = requestEvent.request; | ||
const url = new URL(req.url); | ||
url.host = req.headers.get("X-Deno-Worker-Host") || url.host; | ||
url.protocol = req.headers.get("X-Deno-Worker-Protocol") + ":"; | ||
url.port = req.headers.get("X-Deno-Worker-Port") || url.port; | ||
req = new Request(url.toString(), req); | ||
req.headers.delete("X-Deno-Worker-Host"); | ||
req.headers.delete("X-Deno-Worker-Protocol"); | ||
req.headers.delete("X-Deno-Worker-Port"); | ||
|
||
await requestEvent.respondWith(handler.default(req)); | ||
})(); | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.