Files
sweet/src/server/mod.ts
T
Luca Casonato 75afa6daca feat: add static file support (#58)
This commit adds support for serving static files. Static can be placed
into the `/static` directory (as a sibling of the `/pages` directory).
2021-09-25 13:37:46 +02:00

20 lines
648 B
TypeScript

import { ServerContext } from "./context.ts";
import { listenAndServe } from "./deps.ts";
import { PageModule, RendererModule } from "./types.ts";
export type { Handler, HandlerContext, Handlers } from "./types.ts";
export { RenderContext } from "./render.tsx";
export type { RenderFn } from "./render.tsx";
export interface Routes {
pages: Record<string, PageModule | RendererModule>;
baseUrl: string;
}
export { ServerContext };
export async function start(routes: Routes) {
const ctx = await ServerContext.fromRoutes(routes);
console.log("Server listening on http://localhost:8000");
await listenAndServe(":8000", ctx.handler());
}