From c3938dc7035c60eadc5989e7ea7121772ee7e1a4 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Sun, 15 Oct 2023 08:53:53 +0200 Subject: [PATCH] chore: remove ServerContext from start server (#1942) --- src/dev/dev_command.ts | 4 ++-- src/server/boot.ts | 7 ++----- src/server/mod.ts | 4 ++-- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/dev/dev_command.ts b/src/dev/dev_command.ts index 177af317..dfebac18 100644 --- a/src/dev/dev_command.ts +++ b/src/dev/dev_command.ts @@ -3,7 +3,7 @@ import { DAY, dirname, fromFileUrl, join, toFileUrl } from "./deps.ts"; import { FreshConfig, Manifest as ServerManifest } from "../server/mod.ts"; import { build } from "./build.ts"; import { collect, ensureMinDenoVersion, generate, Manifest } from "./mod.ts"; -import { startFromContext } from "../server/boot.ts"; +import { startServer } from "../server/boot.ts"; import { getFreshConfigWithDefaults } from "../server/config.ts"; import { getServerContext } from "$fresh/src/server/context.ts"; @@ -54,7 +54,7 @@ export async function dev( configWithDefaults.dev = true; configWithDefaults.loadSnapshot = false; const ctx = await getServerContext(configWithDefaults); - await startFromContext(ctx, configWithDefaults.server); + await startServer(ctx.handler(), configWithDefaults.server); } else { // Legacy entry point: Back then `dev.ts` would call `main.ts` but // this causes duplicate plugin instantiation if both `dev.ts` and diff --git a/src/server/boot.ts b/src/server/boot.ts index bf44efdf..13dd9f0d 100644 --- a/src/server/boot.ts +++ b/src/server/boot.ts @@ -1,9 +1,8 @@ -import { ServerContext } from "./context.ts"; import { colors } from "./deps.ts"; import { ServeHandler } from "./types.ts"; -export async function startFromContext( - ctx: ServerContext, +export async function startServer( + handler: Deno.ServeHandler, opts: Partial, ) { if (!opts.onListen) { @@ -24,8 +23,6 @@ export async function startFromContext( opts.port ??= parseInt(portEnv, 10); } - const handler = ctx.handler(); - if (opts.port) { await bootServer(handler, opts); } else { diff --git a/src/server/mod.ts b/src/server/mod.ts index d65b9603..642a48a1 100644 --- a/src/server/mod.ts +++ b/src/server/mod.ts @@ -13,7 +13,7 @@ import { ServeHandlerInfo, UnknownHandler, } from "./types.ts"; -import { startFromContext } from "./boot.ts"; +import { startServer } from "./boot.ts"; export { defineApp, defineConfig, @@ -101,5 +101,5 @@ export async function start(manifest: Manifest, config: FreshConfig = {}) { skipSnapshot: false, dev: false, }); - await startFromContext(ctx, config.server ?? config); + await startServer(ctx.handler(), config.server ?? config); }