feat: move to Deno.serve (#1427)

Co-authored-by: Marvin Hagemeister <marvin@deno.com>
This commit is contained in:
Lino Le Van
2023-07-12 14:37:53 +02:00
committed by GitHub
co-authored by Marvin Hagemeister
parent 46ae49d654
commit e2a1bf8643
24 changed files with 67 additions and 151 deletions
+5 -5
View File
@@ -1,5 +1,4 @@
import {
ConnInfo,
dirname,
extname,
fromFileUrl,
@@ -33,6 +32,7 @@ import {
Route,
RouteModule,
RouterOptions,
ServeHandlerInfo,
UnknownPage,
UnknownPageModule,
} from "./types.ts";
@@ -47,7 +47,7 @@ import {
} from "../build/mod.ts";
import { InternalRoute } from "./router.ts";
const DEFAULT_CONN_INFO: ConnInfo = {
const DEFAULT_CONN_INFO: ServeHandlerInfo = {
localAddr: { transport: "tcp", hostname: "localhost", port: 8080 },
remoteAddr: { transport: "tcp", hostname: "localhost", port: 1234 },
};
@@ -374,7 +374,7 @@ export class ServerContext {
* This functions returns a request handler that handles all routes required
* by fresh, including static files.
*/
handler(): (req: Request, connInfo?: ConnInfo) => Promise<Response> {
handler(): (req: Request, connInfo?: ServeHandlerInfo) => Promise<Response> {
const handlers = this.#handlers();
const inner = router.router<RouterState>(handlers);
const withMiddlewares = this.#composeMiddlewares(
@@ -385,7 +385,7 @@ export class ServerContext {
const trailingSlashEnabled = this.#routerOptions?.trailingSlash;
return async function handler(
req: Request,
connInfo: ConnInfo = DEFAULT_CONN_INFO,
connInfo: ServeHandlerInfo = DEFAULT_CONN_INFO,
) {
// Redirect requests that end with a trailing slash to their non-trailing
// slash counterpart.
@@ -457,7 +457,7 @@ export class ServerContext {
) {
return (
req: Request,
connInfo: ConnInfo,
connInfo: ServeHandlerInfo,
inner: router.FinalHandler<RouterState>,
) => {
// identify middlewares to apply, if any.