Files
sweet/src/server/mod.ts
T
Luca Casonato 70d1838cad BREAKING: make render fn an option on start (#260)
This commit removes the `_render.{tj}s{x}?` file in favor of a `render` option on the `start` call in `main.ts`.
2022-06-20 13:40:23 +02:00

50 lines
1.0 KiB
TypeScript

import { ServerContext } from "./context.ts";
import { serve } from "./deps.ts";
import {
AppModule,
ErrorPageModule,
IslandModule,
MiddlewareModule,
PageModule,
StartOptions,
UnknownPageModule,
} from "./types.ts";
export type {
FreshOptions,
Handler,
HandlerContext,
Handlers,
MiddlewareHandlerContext,
RenderFunction,
} from "./types.ts";
export { RenderContext } from "./render.tsx";
export type { InnerRenderFunction } from "./render.tsx";
export interface Manifest {
routes: Record<
string,
| PageModule
| MiddlewareModule
| AppModule
| ErrorPageModule
| UnknownPageModule
>;
islands: Record<string, IslandModule>;
baseUrl: string;
}
export { ServerContext };
export async function start(
routes: Manifest,
opts: StartOptions = {},
) {
const ctx = await ServerContext.fromManifest(routes, opts);
console.log(
`Server listening on http://${opts?.hostname ?? "localhost"}:${
opts?.port ?? 8000
}`,
);
await serve(ctx.handler(), opts);
}