feat: support specifying hostname and port in start (#150)
Co-authored-by: Luca Casonato <hello@lcas.dev>
This commit is contained in:
co-authored by
Luca Casonato
parent
bb9fa4a09f
commit
34dc19a2f9
@@ -12,6 +12,7 @@ export { serve } from "https://deno.land/std@0.128.0/http/server.ts";
|
|||||||
export type {
|
export type {
|
||||||
ConnInfo,
|
ConnInfo,
|
||||||
Handler as RequestHandler,
|
Handler as RequestHandler,
|
||||||
|
ServeInit,
|
||||||
} from "https://deno.land/std@0.128.0/http/server.ts";
|
} from "https://deno.land/std@0.128.0/http/server.ts";
|
||||||
|
|
||||||
// -- router --
|
// -- router --
|
||||||
|
|||||||
+11
-5
@@ -7,6 +7,7 @@ import {
|
|||||||
MiddlewareModule,
|
MiddlewareModule,
|
||||||
PageModule,
|
PageModule,
|
||||||
RendererModule,
|
RendererModule,
|
||||||
|
StartOptions,
|
||||||
UnknownPageModule,
|
UnknownPageModule,
|
||||||
} from "./types.ts";
|
} from "./types.ts";
|
||||||
export type {
|
export type {
|
||||||
@@ -34,10 +35,15 @@ export interface Manifest {
|
|||||||
|
|
||||||
export { ServerContext };
|
export { ServerContext };
|
||||||
|
|
||||||
export async function start(routes: Manifest) {
|
export async function start(
|
||||||
|
routes: Manifest,
|
||||||
|
opts?: StartOptions,
|
||||||
|
) {
|
||||||
const ctx = await ServerContext.fromManifest(routes);
|
const ctx = await ServerContext.fromManifest(routes);
|
||||||
console.log("Server listening on http://localhost:8000");
|
console.log(
|
||||||
await serve(ctx.handler(), {
|
`Server listening on http://${opts?.hostname ?? "localhost"}:${
|
||||||
port: 8000,
|
opts?.port ?? 8000
|
||||||
});
|
}`,
|
||||||
|
);
|
||||||
|
await serve(ctx.handler(), opts);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -1,5 +1,5 @@
|
|||||||
import { ComponentType } from "../runtime/deps.ts";
|
import { ComponentType } from "../runtime/deps.ts";
|
||||||
import { ConnInfo, router } from "./deps.ts";
|
import { ConnInfo, router, ServeInit } from "./deps.ts";
|
||||||
import {
|
import {
|
||||||
AppProps,
|
AppProps,
|
||||||
ErrorPageProps,
|
ErrorPageProps,
|
||||||
@@ -9,6 +9,8 @@ import {
|
|||||||
} from "../runtime/types.ts";
|
} from "../runtime/types.ts";
|
||||||
import { RenderContext, RenderFn } from "./render.tsx";
|
import { RenderContext, RenderFn } from "./render.tsx";
|
||||||
|
|
||||||
|
export type StartOptions = ServeInit;
|
||||||
|
|
||||||
export interface PageModule {
|
export interface PageModule {
|
||||||
default?: ComponentType<PageProps>;
|
default?: ComponentType<PageProps>;
|
||||||
handler?: Handler | Handlers;
|
handler?: Handler | Handlers;
|
||||||
|
|||||||
Reference in New Issue
Block a user