-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
2,562 additions
and
1 deletion.
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,39 @@ | ||
name: ci | ||
|
||
on: [push] | ||
|
||
jobs: | ||
test: | ||
name: Test | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest] | ||
node-version: [20.x] | ||
deno-version: [1.40.x] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Use Deno Version ${{ matrix.deno-version }} | ||
uses: denolib/setup-deno@master | ||
with: | ||
deno-version: ${{ matrix.deno-version }} | ||
- name: npm install | ||
run: npm ci | ||
env: | ||
CI: true | ||
- name: build | ||
run: npm run build | ||
env: | ||
CI: true | ||
- name: vitest | ||
run: npm run test | ||
env: | ||
CI: true | ||
- name: deno lint | ||
run: | | ||
cd deno-bootstrap | ||
deno lint |
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,2 +1,3 @@ | ||
node_modules | ||
.DS_Store | ||
.DS_Store | ||
dist |
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 @@ | ||
{"lock": false} |
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,57 @@ | ||
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(); | ||
} | ||
})(); | ||
|
||
// serveHttp is deprecated, but we don't have many other options if we'd like to | ||
// keep this pattern of rejecting future connections at the TCP level. | ||
// https://discord.com/channels/684898665143206084/1232398264947445810/1234614780111880303 | ||
// | ||
// deno-lint-ignore no-deprecated-deno-api | ||
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)); | ||
})(); | ||
} |
Oops, something went wrong.