From da340daeb2d6394bdec7fc0590dd7cf61f2f0332 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 21 Jun 2022 15:21:07 +0200 Subject: [PATCH] BREAKING: move a bunch of types into server/ (#263) Moved some server only types like `RouteConfig` into server/. They were previously in runtime/. --- docs/concepts/routes.md | 5 +- docs/getting-started/dynamic-routes.md | 2 +- docs/getting-started/fetching-data.md | 3 +- docs/getting-started/form-submissions.md | 3 +- init.ts | 2 +- runtime.ts | 1 - src/runtime/types.ts | 70 ------- src/server/context.ts | 85 ++++---- src/server/default_error_page.tsx | 2 +- src/server/mod.ts | 14 +- src/server/render.tsx | 16 +- src/server/types.ts | 246 +++++++++++++++-------- tests/fixture/routes/_404.tsx | 2 +- tests/fixture/routes/_500.tsx | 2 +- tests/fixture/routes/_app.tsx | 3 +- tests/fixture/routes/books/[id].tsx | 2 +- tests/fixture/routes/intercept_args.tsx | 3 +- tests/fixture/routes/params.tsx | 4 +- tests/fixture/routes/props/[id].tsx | 2 +- tests/fixture/routes/wildcard.tsx | 2 +- www/routes/docs/[...slug].tsx | 4 +- www/routes/index.tsx | 3 +- 22 files changed, 245 insertions(+), 231 deletions(-) delete mode 100644 src/runtime/types.ts diff --git a/docs/concepts/routes.md b/docs/concepts/routes.md index e93df999..ad550bcc 100644 --- a/docs/concepts/routes.md +++ b/docs/concepts/routes.md @@ -42,7 +42,7 @@ Now, let's render some HTML using the route component. Another example: /** @jsx h */ import { h } from "preact"; -import { PageProps } from "$fresh/runtime.ts"; +import { PageProps } from "$fresh/server.ts"; export default function Page(props: PageProps) { return
You are on the page '{props.url.href}'.
; @@ -65,8 +65,7 @@ response after rendering the page component. /** @jsx h */ import { h } from "preact"; -import { PageProps } from "$fresh/runtime.ts"; -import { HandlerContext, Handlers } from "$fresh/server.ts"; +import { HandlerContext, Handlers, PageProps } from "$fresh/server.ts"; export const handler: Handlers = { async GET(ctx: HandlerContext) { diff --git a/docs/getting-started/dynamic-routes.md b/docs/getting-started/dynamic-routes.md index e7f542fe..8cb16a03 100644 --- a/docs/getting-started/dynamic-routes.md +++ b/docs/getting-started/dynamic-routes.md @@ -29,7 +29,7 @@ as arguments in it's `props` object though. /** @jsx h */ import { h } from "preact"; -import { PageProps } from "$fresh/runtime.ts"; +import { PageProps } from "$fresh/server.ts"; export default function GreetPage(props: PageProps) { const { name } = props.params; diff --git a/docs/getting-started/fetching-data.md b/docs/getting-started/fetching-data.md index 80ed6078..8663225d 100644 --- a/docs/getting-started/fetching-data.md +++ b/docs/getting-started/fetching-data.md @@ -25,8 +25,7 @@ renders it in a page component. /** @jsx h */ import { h } from "preact"; -import { PageProps } from "$fresh/runtime.ts"; -import { Handlers } from "$fresh/server.ts"; +import { Handlers, PageProps } from "$fresh/server.ts"; interface User { login: string; diff --git a/docs/getting-started/form-submissions.md b/docs/getting-started/form-submissions.md index 43dcecfb..9fd1b5bd 100644 --- a/docs/getting-started/form-submissions.md +++ b/docs/getting-started/form-submissions.md @@ -34,8 +34,7 @@ server side: /** @jsx h */ import { h } from "preact"; -import { PageProps } from "$fresh/runtime.ts"; -import { Handlers } from "$fresh/server.ts"; +import { Handlers, PageProps } from "$fresh/server.ts"; const NAMES = ["Alice", "Bob", "Charlie", "Dave", "Eve", "Frank"]; diff --git a/init.ts b/init.ts index e3609e1c..a1fa7f7a 100644 --- a/init.ts +++ b/init.ts @@ -166,7 +166,7 @@ await Deno.writeTextFile( const ROUTES_GREET_TSX = `/** @jsx h */ import { h } from "preact"; -import { PageProps } from "$fresh/runtime.ts"; +import { PageProps } from "$fresh/server.ts"; export default function Greet(props: PageProps) { return
Hello {props.params.name}
; diff --git a/runtime.ts b/runtime.ts index eaeeea24..3a8a6bb7 100644 --- a/runtime.ts +++ b/runtime.ts @@ -1,4 +1,3 @@ -export * from "./src/runtime/types.ts"; export * from "./src/runtime/utils.ts"; export * from "./src/runtime/head.ts"; export * from "./src/runtime/csp.ts"; diff --git a/src/runtime/types.ts b/src/runtime/types.ts deleted file mode 100644 index de5f0f40..00000000 --- a/src/runtime/types.ts +++ /dev/null @@ -1,70 +0,0 @@ -import { ComponentType } from "preact"; - -// deno-lint-ignore no-explicit-any -export interface PageProps { - /** The URL of the request that resulted in this page being rendered. */ - url: URL; - - /** The route matcher (e.g. /blog/:id) that the request matched for this page - * to be rendered. */ - route: string; - - /** - * The paramteres that were matched from the route. - * - * For the `/foo/:bar` route with url `/foo/123`, `params` would be - * `{ bar: '123' }`. For a route with no matchers, `params` would be `{}`. For - * a wildcard route, like `/foo/:path*` with url `/foo/bar/baz`, `params` would - * be `{ path: 'bar/baz' }`. - */ - params: Record; - - /** - * Additional data passed into `HandlerContext.render`. Defaults to - * `undefined`. - */ - data: T; -} - -export interface AppProps { - Component: ComponentType>; -} - -export interface UnknownPageProps { - /** The URL of the request that resulted in this page being rendered. */ - url: URL; - - /** The route matcher (e.g. /blog/:id) that the request matched for this page - * to be rendered. */ - route: string; -} - -export interface ErrorPageProps { - /** The URL of the request that resulted in this page being rendered. */ - url: URL; - - /** The route matcher (e.g. /blog/:id) that the request matched for this page - * to be rendered. */ - route: string; - - /** The error that caused the error page to be loaded. */ - error: unknown; -} - -export interface RouteConfig { - /** - * A route override for the page. This is useful for pages where the route - * can not be expressed through the filesystem routing capabilities. - * - * The route override must be a path-to-regexp compatible route matcher. - */ - routeOverride?: string; - - /** - * If Content-Security-Policy should be enabled for this page. If 'true', a - * locked down policy will be used that allows only the scripts and styles - * that are generated by fresh. Additional scripts and styles can be added - * using the `useCSP` hook. - */ - csp?: boolean; -} diff --git a/src/server/context.ts b/src/server/context.ts index 405494a5..484475b7 100644 --- a/src/server/context.ts +++ b/src/server/context.ts @@ -23,10 +23,9 @@ import { Middleware, MiddlewareModule, MiddlewareRoute, - Page, - PageModule, RenderFunction, - RouterState, + Route, + RouteModule, UnknownPage, UnknownPageModule, } from "./types.ts"; @@ -34,6 +33,10 @@ import { render as internalRender } from "./render.tsx"; import { ContentSecurityPolicyDirectives, SELF } from "../runtime/csp.ts"; import { ASSET_CACHE_BUST_KEY, INTERNAL_PREFIX } from "../runtime/utils.ts"; +interface RouterState { + state: Record; +} + interface StaticFile { /** The URL to the static file on disk. */ localUrl: URL; @@ -49,7 +52,7 @@ interface StaticFile { export class ServerContext { #dev: boolean; - #pages: Page[]; + #routes: Route[]; #islands: Island[]; #staticFiles: StaticFile[]; #bundler: Bundler; @@ -60,7 +63,7 @@ export class ServerContext { #error: ErrorPage; constructor( - pages: Page[], + routes: Route[], islands: Island[], staticFiles: StaticFile[], renderfn: RenderFunction, @@ -70,7 +73,7 @@ export class ServerContext { error: ErrorPage, importMapURL: URL, ) { - this.#pages = pages; + this.#routes = routes; this.#islands = islands; this.#staticFiles = staticFiles; this.#renderFn = renderfn; @@ -94,7 +97,7 @@ export class ServerContext { const importMapURL = new URL("./import_map.json", manifest.baseUrl); // Extract all routes, and prepare them into the `Page` structure. - const pages: Page[] = []; + const routes: Route[] = []; const islands: Island[] = []; const middlewares: MiddlewareRoute[] = []; let app: AppModule = DEFAULT_APP; @@ -112,12 +115,12 @@ export class ServerContext { path.endsWith("/_middleware.ts") || path.endsWith("/_middleware.jsx") || path.endsWith("/_middleware.js"); if (!path.startsWith("/_") && !isMiddleware) { - const { default: component, config } = (module as PageModule); - let route = pathToRoute(baseRoute); + const { default: component, config } = (module as RouteModule); + let pattern = pathToPattern(baseRoute); if (config?.routeOverride) { - route = String(config.routeOverride); + pattern = String(config.routeOverride); } - let { handler } = (module as PageModule); + let { handler } = (module as RouteModule); handler ??= {}; if ( component && @@ -125,15 +128,15 @@ export class ServerContext { ) { handler.GET = (_req, { render }) => render(); } - const page: Page = { - route, + const route: Route = { + pattern, url, name, component, handler, csp: Boolean(config?.csp ?? false), }; - pages.push(page); + routes.push(route); } else if (isMiddleware) { middlewares.push({ ...middlewarePathToPattern(baseRoute), @@ -155,7 +158,7 @@ export class ServerContext { } notFound = { - route: pathToRoute(baseRoute), + pattern: pathToPattern(baseRoute), url, name, component, @@ -173,7 +176,7 @@ export class ServerContext { } error = { - route: pathToRoute(baseRoute), + pattern: pathToPattern(baseRoute), url, name, component, @@ -183,7 +186,7 @@ export class ServerContext { }; } } - sortRoutes(pages); + sortRoutes(routes); sortRoutes(middlewares); for (const [self, module] of Object.entries(manifest.islands)) { @@ -249,7 +252,7 @@ export class ServerContext { } return new ServerContext( - pages, + routes, islands, staticFiles, opts.render ?? DEFAULT_RENDER_FN, @@ -266,7 +269,7 @@ export class ServerContext { * by fresh, including static files. */ handler(): RequestHandler { - const inner = router.router(...this.#routes()); + const inner = router.router(...this.#handlers()); const withMiddlewares = this.#composeMiddlewares(this.#middlewares); return function handler(req: Request, connInfo: ConnInfo) { // Redirect requests that end with a trailing slash @@ -321,7 +324,7 @@ export class ServerContext { * This function returns all routes required by fresh as an extended * path-to-regex, to handler mapping. */ - #routes(): [ + #handlers(): [ router.Routes, router.Handler, router.ErrorHandler, @@ -381,7 +384,7 @@ export class ServerContext { } const genRender = ( - page: Page | UnknownPage | ErrorPage, + route: Route | UnknownPage | ErrorPage, status: number, ) => { const imports: string[] = []; @@ -394,12 +397,12 @@ export class ServerContext { error?: unknown, ) => { return async (data?: Data) => { - if (page.component === undefined) { + if (route.component === undefined) { throw new Error("This page does not have a component to render."); } const preloads: string[] = []; const resp = await internalRender({ - page, + route, islands: this.#islands, app: this.#app, imports, @@ -435,18 +438,18 @@ export class ServerContext { }; }; - for (const page of this.#pages) { - const createRender = genRender(page, 200); - if (typeof page.handler === "function") { - routes[page.route] = (req, ctx, params) => - (page.handler as Handler)(req, { + for (const route of this.#routes) { + const createRender = genRender(route, 200); + if (typeof route.handler === "function") { + routes[route.pattern] = (req, ctx, params) => + (route.handler as Handler)(req, { ...ctx, params, render: createRender(req, params), }); } else { - for (const [method, handler] of Object.entries(page.handler)) { - routes[`${method}@${page.route}`] = (req, ctx, params) => + for (const [method, handler] of Object.entries(route.handler)) { + routes[`${method}@${route.pattern}`] = (req, ctx, params) => handler(req, { ...ctx, params, @@ -573,7 +576,7 @@ const DEFAULT_APP: AppModule = { }; const DEFAULT_NOT_FOUND: UnknownPage = { - route: "", + pattern: "", url: "", name: "_404", handler: (req) => router.defaultOtherHandler(req), @@ -581,7 +584,7 @@ const DEFAULT_NOT_FOUND: UnknownPage = { }; const DEFAULT_ERROR: ErrorPage = { - route: "", + pattern: "", url: "", name: "_500", component: DefaultErrorHandler, @@ -598,8 +601,8 @@ export function selectMiddlewares(url: string, middlewares: MiddlewareRoute[]) { const selectedMws: Middleware[] = []; const reqURL = new URL(url); - for (const { pattern, handler } of middlewares) { - const res = pattern.exec(reqURL); + for (const { compiledPattern, handler } of middlewares) { + const res = compiledPattern.exec(reqURL); if (res) { selectedMws.push({ handler }); } @@ -612,10 +615,10 @@ export function selectMiddlewares(url: string, middlewares: MiddlewareRoute[]) { * Sort pages by their relative routing priority, based on the parts in the * route matcher */ -function sortRoutes(routes: T[]) { +function sortRoutes(routes: T[]) { routes.sort((a, b) => { - const partsA = a.route.split("/"); - const partsB = b.route.split("/"); + const partsA = a.pattern.split("/"); + const partsB = b.pattern.split("/"); for (let i = 0; i < Math.max(partsA.length, partsB.length); i++) { const partA = partsA[i]; const partB = partsB[i]; @@ -631,7 +634,7 @@ function sortRoutes(routes: T[]) { } /** Transform a filesystem URL path to a `path-to-regex` style matcher. */ -function pathToRoute(path: string): string { +function pathToPattern(path: string): string { const parts = path.split("/"); if (parts[parts.length - 1] === "index") { parts.pop(); @@ -687,7 +690,7 @@ function serializeCSPDirectives(csp: ContentSecurityPolicyDirectives): string { export function middlewarePathToPattern(baseRoute: string) { baseRoute = baseRoute.slice(0, -"_middleware".length); - const regRoute = pathToRoute(baseRoute); - const pattern = new URLPattern({ pathname: `${regRoute}*` }); - return { route: regRoute, pattern }; + const pattern = pathToPattern(baseRoute); + const compiledPattern = new URLPattern({ pathname: `${pattern}*` }); + return { pattern, compiledPattern }; } diff --git a/src/server/default_error_page.tsx b/src/server/default_error_page.tsx index c919fb68..360091bd 100644 --- a/src/server/default_error_page.tsx +++ b/src/server/default_error_page.tsx @@ -2,7 +2,7 @@ import { h } from "preact"; import { DEBUG } from "./constants.ts"; -import type { ErrorPageProps } from "../runtime/types.ts"; +import type { ErrorPageProps } from "./types.ts"; export default function DefaultErrorPage(props: ErrorPageProps) { const { error } = props; diff --git a/src/server/mod.ts b/src/server/mod.ts index b5e68661..34446a34 100644 --- a/src/server/mod.ts +++ b/src/server/mod.ts @@ -5,17 +5,27 @@ import { ErrorPageModule, IslandModule, MiddlewareModule, - PageModule, + RouteModule, StartOptions, UnknownPageModule, } from "./types.ts"; export type { + AppProps, + ErrorHandler, + ErrorHandlerContext, + ErrorPageProps, FreshOptions, Handler, HandlerContext, Handlers, MiddlewareHandlerContext, + PageProps, RenderFunction, + RouteConfig, + StartOptions, + UnknownHandler, + UnknownHandlerContext, + UnknownPageProps, } from "./types.ts"; export { RenderContext } from "./render.tsx"; export type { InnerRenderFunction } from "./render.tsx"; @@ -23,7 +33,7 @@ export type { InnerRenderFunction } from "./render.tsx"; export interface Manifest { routes: Record< string, - | PageModule + | RouteModule | MiddlewareModule | AppModule | ErrorPageModule diff --git a/src/server/render.tsx b/src/server/render.tsx index b14784e3..38c9dfc7 100644 --- a/src/server/render.tsx +++ b/src/server/render.tsx @@ -5,8 +5,8 @@ import { AppModule, ErrorPage, Island, - Page, RenderFunction, + Route, UnknownPage, } from "./types.ts"; import { HEAD_CONTEXT } from "../runtime/head.ts"; @@ -16,7 +16,7 @@ import { bundleAssetUrl } from "./constants.ts"; import { assetHashingHook } from "../runtime/utils.ts"; export interface RenderOptions { - page: Page | UnknownPage | ErrorPage; + route: Route | UnknownPage | ErrorPage; islands: Island[]; app: AppModule; imports: string[]; @@ -123,14 +123,14 @@ export async function render( const props: Record = { params: opts.params, url: opts.url, - route: opts.page.route, + route: opts.route.pattern, data: opts.data, }; if (opts.error) { props.error = opts.error; } - const csp: ContentSecurityPolicy | undefined = opts.page.csp + const csp: ContentSecurityPolicy | undefined = opts.route.csp ? defaultCsp() : undefined; const headComponents: ComponentChildren[] = []; @@ -141,13 +141,17 @@ export async function render( value: headComponents, children: h(opts.app.default, { Component() { - return h(opts.page.component! as ComponentType, props); + return h(opts.route.component! as ComponentType, props); }, }), }), }); - const ctx = new RenderContext(crypto.randomUUID(), opts.url, opts.page.route); + const ctx = new RenderContext( + crypto.randomUUID(), + opts.url, + opts.route.pattern, + ); if (csp) { // Clear the csp diff --git a/src/server/types.ts b/src/server/types.ts index 489bbf35..8cbc0b16 100644 --- a/src/server/types.ts +++ b/src/server/types.ts @@ -1,17 +1,8 @@ import { ComponentType } from "preact"; import { ConnInfo, router, ServeInit } from "./deps.ts"; -import { - AppProps, - ErrorPageProps, - PageProps, - RouteConfig, - UnknownPageProps, -} from "../runtime/types.ts"; import { InnerRenderFunction, RenderContext } from "./render.tsx"; -export interface RouterState { - state: Record; -} +// --- APPLICATION CONFIGURATION --- export type StartOptions = ServeInit & FreshOptions; @@ -24,28 +15,50 @@ export type RenderFunction = ( render: InnerRenderFunction, ) => void | Promise; -export interface PageModule { - default?: ComponentType; - // deno-lint-ignore no-explicit-any - handler?: Handler | Handlers; - config?: RouteConfig; +/// --- ROUTES --- + +// deno-lint-ignore no-explicit-any +export interface PageProps { + /** The URL of the request that resulted in this page being rendered. */ + url: URL; + + /** The route matcher (e.g. /blog/:id) that the request matched for this page + * to be rendered. */ + route: string; + + /** + * The paramteres that were matched from the route. + * + * For the `/foo/:bar` route with url `/foo/123`, `params` would be + * `{ bar: '123' }`. For a route with no matchers, `params` would be `{}`. For + * a wildcard route, like `/foo/:path*` with url `/foo/bar/baz`, `params` would + * be `{ path: 'bar/baz' }`. + */ + params: Record; + + /** + * Additional data passed into `HandlerContext.render`. Defaults to + * `undefined`. + */ + data: T; } -export interface UnknownPageModule { - default?: ComponentType; - handler?: UnknownHandler; - config?: RouteConfig; -} +export interface RouteConfig { + /** + * A route override for the page. This is useful for pages where the route + * can not be expressed through the filesystem routing capabilities. + * + * The route override must be a path-to-regexp compatible route matcher. + */ + routeOverride?: string; -export interface ErrorPageModule { - default?: ComponentType; - handler?: ErrorHandler; - config?: RouteConfig; -} - -export interface IslandModule { - // deno-lint-ignore no-explicit-any - default: ComponentType; + /** + * If Content-Security-Policy should be enabled for this page. If 'true', a + * locked down policy will be used that allows only the scripts and styles + * that are generated by fresh. Additional scripts and styles can be added + * using the `useCSP` hook. + */ + csp?: boolean; } export interface HandlerContext> @@ -55,18 +68,122 @@ export interface HandlerContext> state: State; } +// deno-lint-ignore no-explicit-any +export type Handler> = ( + req: Request, + ctx: HandlerContext, +) => Response | Promise; + +// deno-lint-ignore no-explicit-any +export type Handlers> = { + [K in typeof router.METHODS[number]]?: Handler; +}; + +export interface RouteModule { + default?: ComponentType; + // deno-lint-ignore no-explicit-any + handler?: Handler | Handlers; + config?: RouteConfig; +} + +// deno-lint-ignore no-explicit-any +export interface Route { + pattern: string; + url: string; + name: string; + component?: ComponentType>; + handler: Handler | Handlers; + csp: boolean; +} + +// --- APP --- + +export interface AppProps { + Component: ComponentType>; +} + +export interface AppModule { + default: ComponentType; +} + +// --- UNKNOWN PAGE --- + +export interface UnknownPageProps { + /** The URL of the request that resulted in this page being rendered. */ + url: URL; + + /** The route matcher (e.g. /blog/:id) that the request matched for this page + * to be rendered. */ + route: string; +} + export interface UnknownHandlerContext> extends ConnInfo { render: () => Response | Promise; state: State; } +export type UnknownHandler = ( + req: Request, + ctx: UnknownHandlerContext, +) => Response | Promise; + +export interface UnknownPageModule { + default?: ComponentType; + handler?: UnknownHandler; + config?: RouteConfig; +} + +export interface UnknownPage { + pattern: string; + url: string; + name: string; + component?: ComponentType; + handler: UnknownHandler; + csp: boolean; +} + +// --- ERROR PAGE --- + +export interface ErrorPageProps { + /** The URL of the request that resulted in this page being rendered. */ + url: URL; + + /** The route matcher (e.g. /blog/:id) that the request matched for this page + * to be rendered. */ + pattern: string; + + /** The error that caused the error page to be loaded. */ + error: unknown; +} + export interface ErrorHandlerContext> extends ConnInfo { error: unknown; render: () => Response | Promise; state: State; } +export type ErrorHandler = ( + req: Request, + ctx: ErrorHandlerContext, +) => Response | Promise; + +export interface ErrorPageModule { + default?: ComponentType; + handler?: ErrorHandler; + config?: RouteConfig; +} + +export interface ErrorPage { + pattern: string; + url: string; + name: string; + component?: ComponentType; + handler: ErrorHandler; + csp: boolean; +} + +// --- MIDDLEWARES --- export interface MiddlewareHandlerContext> extends ConnInfo { @@ -74,51 +191,15 @@ export interface MiddlewareHandlerContext> state: State; } -// deno-lint-ignore no-explicit-any -export type Handler> = ( - req: Request, - ctx: HandlerContext, -) => Response | Promise; -export type UnknownHandler = ( - req: Request, - ctx: UnknownHandlerContext, -) => Response | Promise; -export type ErrorHandler = ( - req: Request, - ctx: ErrorHandlerContext, -) => Response | Promise; - -// deno-lint-ignore no-explicit-any -export type Handlers> = { - [K in typeof router.METHODS[number]]?: Handler; -}; - -// deno-lint-ignore no-explicit-any -export interface Page { - route: string; - url: string; - name: string; - component?: ComponentType>; - handler: Handler | Handlers; - csp: boolean; -} - -export interface UnknownPage { - route: string; - url: string; - name: string; - component?: ComponentType; - handler: UnknownHandler; - csp: boolean; -} - -export interface ErrorPage { - route: string; - url: string; - name: string; - component?: ComponentType; - handler: ErrorHandler; - csp: boolean; +export interface MiddlewareRoute extends Middleware { + /** + * path-to-regexp style url path + */ + pattern: string; + /** + * URLPattern of the route + */ + compiledPattern: URLPattern; } // deno-lint-ignore no-explicit-any @@ -136,20 +217,11 @@ export interface Middleware> { ): Response | Promise; } -export interface MiddlewareRoute extends Middleware { - /** - * path-to-regexp style url path - */ - route: string; - /** - * URLPattern of the route - */ - // deno-lint-ignore no-explicit-any - pattern: any; -} +// --- ISLANDS --- -export interface AppModule { - default: ComponentType; +export interface IslandModule { + // deno-lint-ignore no-explicit-any + default: ComponentType; } export interface Island { diff --git a/tests/fixture/routes/_404.tsx b/tests/fixture/routes/_404.tsx index f811202a..b5a57361 100644 --- a/tests/fixture/routes/_404.tsx +++ b/tests/fixture/routes/_404.tsx @@ -1,6 +1,6 @@ /** @jsx h */ import { h } from "preact"; -import { UnknownPageProps } from "$fresh/runtime.ts"; +import { UnknownPageProps } from "$fresh/server.ts"; export default function NotFoundPage({ url }: UnknownPageProps) { return

404 not found: {url.pathname}

; diff --git a/tests/fixture/routes/_500.tsx b/tests/fixture/routes/_500.tsx index 5ec54a16..a4fbc35d 100644 --- a/tests/fixture/routes/_500.tsx +++ b/tests/fixture/routes/_500.tsx @@ -1,6 +1,6 @@ /** @jsx h */ import { h } from "preact"; -import { ErrorPageProps } from "$fresh/runtime.ts"; +import { ErrorPageProps } from "$fresh/server.ts"; export default function Error500Page({ error }: ErrorPageProps) { return

500 internal error: {(error as Error).message}

; diff --git a/tests/fixture/routes/_app.tsx b/tests/fixture/routes/_app.tsx index 72d80cdb..6216d837 100644 --- a/tests/fixture/routes/_app.tsx +++ b/tests/fixture/routes/_app.tsx @@ -1,7 +1,8 @@ /** @jsx h */ /** @jsxFrag Fragment */ import { Fragment, h } from "preact"; -import { AppProps, Head } from "$fresh/runtime.ts"; +import { Head } from "$fresh/runtime.ts"; +import { AppProps } from "$fresh/server.ts"; export default function App(props: AppProps) { return ( diff --git a/tests/fixture/routes/books/[id].tsx b/tests/fixture/routes/books/[id].tsx index efc90bf3..a3c49abe 100644 --- a/tests/fixture/routes/books/[id].tsx +++ b/tests/fixture/routes/books/[id].tsx @@ -1,6 +1,6 @@ /** @jsx h */ import { h } from "preact"; -import { PageProps, RouteConfig } from "$fresh/runtime.ts"; +import { PageProps, RouteConfig } from "$fresh/server.ts"; export default function Page(props: PageProps) { return
Book {props.params.id}
; diff --git a/tests/fixture/routes/intercept_args.tsx b/tests/fixture/routes/intercept_args.tsx index 6fa84b96..8dca3b17 100644 --- a/tests/fixture/routes/intercept_args.tsx +++ b/tests/fixture/routes/intercept_args.tsx @@ -1,7 +1,6 @@ /** @jsx h */ import { h } from "preact"; -import { PageProps } from "$fresh/runtime.ts"; -import { Handlers } from "$fresh/server.ts"; +import { Handlers, PageProps } from "$fresh/server.ts"; interface Data extends Record { info: string; diff --git a/tests/fixture/routes/params.tsx b/tests/fixture/routes/params.tsx index b66c71b8..dd38cf84 100644 --- a/tests/fixture/routes/params.tsx +++ b/tests/fixture/routes/params.tsx @@ -1,7 +1,5 @@ /** @jsx h */ -import { h } from "preact"; -import { RouteConfig } from "$fresh/runtime.ts"; -import { HandlerContext } from "../../../server.ts"; +import { HandlerContext, RouteConfig } from "$fresh/server.ts"; export const handler = { GET(_req: Request, { params }: HandlerContext) { diff --git a/tests/fixture/routes/props/[id].tsx b/tests/fixture/routes/props/[id].tsx index 6f3beb1b..8a467261 100644 --- a/tests/fixture/routes/props/[id].tsx +++ b/tests/fixture/routes/props/[id].tsx @@ -1,6 +1,6 @@ /** @jsx h */ import { h } from "preact"; -import { PageProps } from "$fresh/runtime.ts"; +import { PageProps } from "$fresh/server.ts"; export default function Home(props: PageProps) { return
{JSON.stringify(props)}
; diff --git a/tests/fixture/routes/wildcard.tsx b/tests/fixture/routes/wildcard.tsx index 819403a4..b0f750c8 100644 --- a/tests/fixture/routes/wildcard.tsx +++ b/tests/fixture/routes/wildcard.tsx @@ -1,6 +1,6 @@ /** @jsx h */ import { h } from "preact"; -import { PageProps, RouteConfig } from "$fresh/runtime.ts"; +import { PageProps, RouteConfig } from "$fresh/server.ts"; export default function WildcardPage({ params }: PageProps) { if (typeof params.path === "string") { diff --git a/www/routes/docs/[...slug].tsx b/www/routes/docs/[...slug].tsx index 68ec8b3c..dda4dacd 100644 --- a/www/routes/docs/[...slug].tsx +++ b/www/routes/docs/[...slug].tsx @@ -1,8 +1,8 @@ /** @jsx h */ /** @jsxFrag Fragment */ import { Fragment, h } from "preact"; -import { Head, PageProps } from "$fresh/runtime.ts"; -import { Handlers } from "$fresh/server.ts"; +import { Head } from "$fresh/runtime.ts"; +import { Handlers, PageProps } from "$fresh/server.ts"; import { apply, tw } from "../../utils/twind.ts"; import { frontMatter, gfm } from "../../utils/markdown.ts"; diff --git a/www/routes/index.tsx b/www/routes/index.tsx index 5b5172c3..ce949c3a 100644 --- a/www/routes/index.tsx +++ b/www/routes/index.tsx @@ -1,7 +1,8 @@ /** @jsx h */ /** @jsxFrag Fragment */ import { ComponentChildren, Fragment, h } from "preact"; -import { asset, Head, PageProps } from "$fresh/runtime.ts"; +import { asset, Head } from "$fresh/runtime.ts"; +import { PageProps } from "$fresh/server.ts"; import { tw } from "../utils/twind.ts"; import Counter from "../islands/Counter.tsx"; import LemonDrop from "../islands/LemonDrop.tsx";