chore: remove ServerContext from start server (#1942)
This commit is contained in:
@@ -3,7 +3,7 @@ import { DAY, dirname, fromFileUrl, join, toFileUrl } from "./deps.ts";
|
|||||||
import { FreshConfig, Manifest as ServerManifest } from "../server/mod.ts";
|
import { FreshConfig, Manifest as ServerManifest } from "../server/mod.ts";
|
||||||
import { build } from "./build.ts";
|
import { build } from "./build.ts";
|
||||||
import { collect, ensureMinDenoVersion, generate, Manifest } from "./mod.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 { getFreshConfigWithDefaults } from "../server/config.ts";
|
||||||
import { getServerContext } from "$fresh/src/server/context.ts";
|
import { getServerContext } from "$fresh/src/server/context.ts";
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ export async function dev(
|
|||||||
configWithDefaults.dev = true;
|
configWithDefaults.dev = true;
|
||||||
configWithDefaults.loadSnapshot = false;
|
configWithDefaults.loadSnapshot = false;
|
||||||
const ctx = await getServerContext(configWithDefaults);
|
const ctx = await getServerContext(configWithDefaults);
|
||||||
await startFromContext(ctx, configWithDefaults.server);
|
await startServer(ctx.handler(), configWithDefaults.server);
|
||||||
} else {
|
} else {
|
||||||
// Legacy entry point: Back then `dev.ts` would call `main.ts` but
|
// Legacy entry point: Back then `dev.ts` would call `main.ts` but
|
||||||
// this causes duplicate plugin instantiation if both `dev.ts` and
|
// this causes duplicate plugin instantiation if both `dev.ts` and
|
||||||
|
|||||||
+2
-5
@@ -1,9 +1,8 @@
|
|||||||
import { ServerContext } from "./context.ts";
|
|
||||||
import { colors } from "./deps.ts";
|
import { colors } from "./deps.ts";
|
||||||
import { ServeHandler } from "./types.ts";
|
import { ServeHandler } from "./types.ts";
|
||||||
|
|
||||||
export async function startFromContext(
|
export async function startServer(
|
||||||
ctx: ServerContext,
|
handler: Deno.ServeHandler,
|
||||||
opts: Partial<Deno.ServeTlsOptions>,
|
opts: Partial<Deno.ServeTlsOptions>,
|
||||||
) {
|
) {
|
||||||
if (!opts.onListen) {
|
if (!opts.onListen) {
|
||||||
@@ -24,8 +23,6 @@ export async function startFromContext(
|
|||||||
opts.port ??= parseInt(portEnv, 10);
|
opts.port ??= parseInt(portEnv, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
const handler = ctx.handler();
|
|
||||||
|
|
||||||
if (opts.port) {
|
if (opts.port) {
|
||||||
await bootServer(handler, opts);
|
await bootServer(handler, opts);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+2
-2
@@ -13,7 +13,7 @@ import {
|
|||||||
ServeHandlerInfo,
|
ServeHandlerInfo,
|
||||||
UnknownHandler,
|
UnknownHandler,
|
||||||
} from "./types.ts";
|
} from "./types.ts";
|
||||||
import { startFromContext } from "./boot.ts";
|
import { startServer } from "./boot.ts";
|
||||||
export {
|
export {
|
||||||
defineApp,
|
defineApp,
|
||||||
defineConfig,
|
defineConfig,
|
||||||
@@ -101,5 +101,5 @@ export async function start(manifest: Manifest, config: FreshConfig = {}) {
|
|||||||
skipSnapshot: false,
|
skipSnapshot: false,
|
||||||
dev: false,
|
dev: false,
|
||||||
});
|
});
|
||||||
await startFromContext(ctx, config.server ?? config);
|
await startServer(ctx.handler(), config.server ?? config);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user