feat: move to Deno.serve (#1427)
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
This commit is contained in:
co-authored by
Marvin Hagemeister
parent
46ae49d654
commit
e2a1bf8643
+12
-5
@@ -1,13 +1,15 @@
|
||||
import { ServerContext } from "./context.ts";
|
||||
import * as colors from "https://deno.land/std@0.193.0/fmt/colors.ts";
|
||||
import { ConnInfo, serve, ServeHandler } from "./deps.ts";
|
||||
export { Status } from "./deps.ts";
|
||||
import { serve } from "./deps.ts";
|
||||
import {
|
||||
AppModule,
|
||||
ErrorPageModule,
|
||||
IslandModule,
|
||||
MiddlewareModule,
|
||||
RouteModule,
|
||||
ServeHandler,
|
||||
ServeHandlerInfo,
|
||||
StartOptions,
|
||||
UnknownPageModule,
|
||||
} from "./types.ts";
|
||||
@@ -35,6 +37,7 @@ export type {
|
||||
PluginRenderStyleTag,
|
||||
RenderFunction,
|
||||
RouteConfig,
|
||||
ServeHandlerInfo,
|
||||
StartOptions,
|
||||
UnknownHandler,
|
||||
UnknownHandlerContext,
|
||||
@@ -70,7 +73,9 @@ export { ServerContext };
|
||||
export async function createHandler(
|
||||
routes: Manifest,
|
||||
opts: StartOptions = {},
|
||||
): Promise<(req: Request, connInfo?: ConnInfo) => Promise<Response>> {
|
||||
): Promise<
|
||||
(req: Request, connInfo?: ServeHandlerInfo) => Promise<Response>
|
||||
> {
|
||||
const ctx = await ServerContext.fromManifest(routes, opts);
|
||||
return ctx.handler();
|
||||
}
|
||||
@@ -132,10 +137,12 @@ export async function start(routes: Manifest, opts: StartOptions = {}) {
|
||||
}
|
||||
|
||||
async function bootServer(handler: ServeHandler, opts: StartOptions) {
|
||||
if (opts.experimentalDenoServe === true) {
|
||||
// @ts-ignore as `Deno.serve` is still unstable.
|
||||
await Deno.serve({ ...opts, handler }).finished;
|
||||
// @ts-ignore Ignore type error when type checking with Deno versions
|
||||
if (typeof Deno.serve === "function") {
|
||||
// @ts-ignore Ignore type error when type checking with Deno versions
|
||||
await Deno.serve(opts, handler).finished;
|
||||
} else {
|
||||
// @ts-ignore Deprecated std serve way
|
||||
await serve(handler, opts);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user