feat: deployctl is not needed anymore (#45)

Deno Deploy now supports Deno.listen and Deno.serveHttp.
This commit is contained in:
Luca Casonato
2021-07-30 14:09:04 +02:00
committed by GitHub
parent 8d2935aef3
commit 3bce2fb8d3
14 changed files with 42 additions and 39 deletions
+6
View File
@@ -2,3 +2,9 @@ export const INTERNAL_PREFIX = "/_frsh";
export const BUILD_ID = Deno.env.get("DENO_DEPLOYMENT_ID") ||
crypto.randomUUID();
export const JS_PREFIX = `/js`;
declare global {
interface Crypto {
randomUUID(): string;
}
}
+2 -1
View File
@@ -50,7 +50,8 @@ export class ServerContext {
if (path.startsWith("/api/")) {
const handlers = Object.fromEntries(
Object.entries(module as ApiRouteModule).filter(([method]) =>
method === "default" || router.METHODS.includes(method)
method === "default" ||
(router.METHODS as readonly string[]).includes(method)
),
);
const apiRoute: ApiRoute = {
+1 -1
View File
@@ -14,4 +14,4 @@ export { lookup as mediaTypeLookup } from "https://deno.land/x/media_types@v2.9.
// @deno-types="https://unpkg.com/esbuild-wasm@0.11.19/esm/browser.d.ts"
import * as esbuild from "https://gist.githubusercontent.com/lucacasonato/358c6b7e8198bfb2cf3d220e49fdcf5f/raw/3714cb0f59606eefc29ed0fea36d4cd93549938b/esbuild-wasm.js";
export { esbuild };
export { denoPlugin } from "https://deno.land/x/esbuild_deno_loader@0.2.0/mod.ts";
export { denoPlugin } from "https://deno.land/x/esbuild_deno_loader@0.3.0/mod.ts";
+19 -3
View File
@@ -14,7 +14,23 @@ export { router, ServerContext };
export function start(routes: Routes) {
const ctx = ServerContext.fromRoutes(routes);
const app = router.router(ctx.routes());
addEventListener("fetch", (event: FetchEvent) => {
event.respondWith(app(event.request));
});
serve(app);
}
async function serve(handler: (req: Request) => Response | Promise<Response>) {
async function handleConn(conn: Deno.Conn) {
const httpConn = Deno.serveHttp(conn);
for await (const e of httpConn) {
e.respondWith(handler(e.request))
.catch((e) => console.error("Failed handing a request:", e));
}
}
const listener = Deno.listen({ port: 8000 });
const addr = listener.addr as Deno.NetAddr;
console.log(`Listening on http://${addr.hostname}:${addr.port}`);
for await (const conn of listener) {
handleConn(conn)
.catch((e) => console.error("Failed serving a connection:", e));
}
}