|
1 | | -import { type ApiMap, type ApiMethod, findEndpoint } from "./api.ts"; |
| 1 | +import { type ApiMethod, findEndpoint } from "./api.ts"; |
2 | 2 | import { escapeHtml, filePathFromModuleUrl } from "./utils.ts"; |
| 3 | +import type { PeraOptions } from "./types.ts"; |
3 | 4 | import { transpile } from "@deno/emit"; |
4 | 5 |
|
5 | 6 | /** |
6 | | - * The options for the Pera app. |
7 | | - */ |
8 | | -export type PeraOptions = { |
9 | | - /** The port to listen on. (Default: 8080) */ |
10 | | - port?: number; |
11 | | - /** The title of the app. This value will be used as the title of the HTML document. (Default: "Pera App") */ |
12 | | - title?: string; |
13 | | - /** The props to pass to the App component. (Default: {}) */ |
14 | | - // deno-lint-ignore no-explicit-any |
15 | | - props?: Record<string, any>; |
16 | | - /** The URL of the module to import the App component from. */ |
17 | | - moduleUrl: string; |
18 | | - /** The ID of the root element to render the App component into. (Default: "root") */ |
19 | | - rootId?: string; |
20 | | - /** Whether to enable hot module replacement. (Default: true) */ |
21 | | - hmr?: boolean; |
22 | | - /** The API endpoints to expose to the client. (Default: {}) */ |
23 | | - api?: ApiMap; |
24 | | -}; |
25 | | - |
26 | | -/** |
27 | | - * Serve the Pera app. serve() implicitly treats a component named App as |
28 | | - * the root component. Therefore, you must define a component named App. |
29 | | - * |
30 | | - * @example Basic Example |
31 | | - * ```ts |
32 | | - * // Make sure to import the serve function in the main module. |
33 | | - * if (import.meta.main) { |
34 | | - * const { serve } = await import("jsr:@d2verb/pera"); |
35 | | - * |
36 | | - * await serve({ |
37 | | - * port: 8080, |
38 | | - * moduleUrl: import.meta.url, |
39 | | - * }); |
40 | | - * } |
41 | | - * ``` |
| 7 | + * The implementation of the serve() function. |
42 | 8 | * |
43 | 9 | * @param opts The options for the Pera app. |
44 | 10 | */ |
45 | | -export function serve(opts: PeraOptions) { |
| 11 | +export function serveImpl(opts: PeraOptions) { |
46 | 12 | const port = opts.port ?? 8080; |
47 | 13 | const title = opts.title ?? "Pera App"; |
48 | 14 | const rootId = opts.rootId ?? "root"; |
|
0 commit comments