refactor(core): minor fresh/compat cleanups (#2880)
This commit is contained in:
@@ -13,7 +13,7 @@
|
|||||||
".": "./src/mod.ts",
|
".": "./src/mod.ts",
|
||||||
"./runtime": "./src/runtime/shared.ts",
|
"./runtime": "./src/runtime/shared.ts",
|
||||||
"./dev": "./src/dev/mod.ts",
|
"./dev": "./src/dev/mod.ts",
|
||||||
"./compat": "./src/compat/mod.ts"
|
"./compat": "./src/compat.ts"
|
||||||
},
|
},
|
||||||
"tasks": {
|
"tasks": {
|
||||||
"test": "deno test -A --parallel",
|
"test": "deno test -A --parallel",
|
||||||
|
|||||||
@@ -1,32 +1,32 @@
|
|||||||
import type { VNode } from "preact";
|
import type { VNode } from "preact";
|
||||||
import type { FreshContext } from "../context.ts";
|
import type { FreshContext } from "./context.ts";
|
||||||
import type { HandlerFn, RouteHandler } from "../handlers.ts";
|
import type { HandlerFn, RouteHandler } from "./handlers.ts";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use {@link PageProps} instead.
|
* @deprecated Use {@linkcode PageProps} instead.
|
||||||
*/
|
*/
|
||||||
export type AppProps<_Data = unknown, T = unknown> = FreshContext<T>;
|
export type AppProps<_Data = unknown, T = unknown> = FreshContext<T>;
|
||||||
/**
|
/**
|
||||||
* @deprecated Use {@link PageProps} instead.
|
* @deprecated Use {@linkcode PageProps} instead.
|
||||||
*/
|
*/
|
||||||
export type LayoutProps<_Data = unknown, T = unknown> = FreshContext<T>;
|
export type LayoutProps<_Data = unknown, T = unknown> = FreshContext<T>;
|
||||||
/**
|
/**
|
||||||
* @deprecated Use {@link PageProps} instead.
|
* @deprecated Use {@linkcode PageProps} instead.
|
||||||
*/
|
*/
|
||||||
export type UnknownPageProps<_Data = unknown, T = unknown> = FreshContext<T>;
|
export type UnknownPageProps<_Data = unknown, T = unknown> = FreshContext<T>;
|
||||||
/**
|
/**
|
||||||
* @deprecated Use {@link PageProps} instead.
|
* @deprecated Use {@linkcode PageProps} instead.
|
||||||
*/
|
*/
|
||||||
export type ErrorPageProps<_Data = unknown, T = unknown> = FreshContext<T>;
|
export type ErrorPageProps<_Data = unknown, T = unknown> = FreshContext<T>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use {@link FreshContext} instead.
|
* @deprecated Use {@linkcode FreshContext} instead.
|
||||||
*/
|
*/
|
||||||
export type RouteContext<_T = never, S = Record<string, unknown>> =
|
export type RouteContext<_T = never, S = Record<string, unknown>> =
|
||||||
FreshContext<S>;
|
FreshContext<S>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use {@link RouteHandler} instead.
|
* @deprecated Use {@linkcode RouteHandler} instead.
|
||||||
*/
|
*/
|
||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
export type Handlers<T = any, State = Record<string, unknown>> = RouteHandler<
|
export type Handlers<T = any, State = Record<string, unknown>> = RouteHandler<
|
||||||
@@ -35,7 +35,7 @@ export type Handlers<T = any, State = Record<string, unknown>> = RouteHandler<
|
|||||||
>;
|
>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use {@link HandlerFn} instead.
|
* @deprecated Use {@linkcode HandlerFn} instead.
|
||||||
*/
|
*/
|
||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
export type Handler<T = any, State = Record<string, unknown>> = HandlerFn<
|
export type Handler<T = any, State = Record<string, unknown>> = HandlerFn<
|
||||||
@@ -54,14 +54,14 @@ function defineFn<State>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use {@link [../mod.ts].Define.page|define.page} instead.
|
* @deprecated Use {@linkcode [./mod.ts].Define.page|define.page} instead.
|
||||||
*/
|
*/
|
||||||
export const defineApp = defineFn;
|
export const defineApp = defineFn;
|
||||||
/**
|
/**
|
||||||
* @deprecated Use {@link [../mod.ts].Define.page|define.page} instead.
|
* @deprecated Use {@linkcode [./mod.ts].Define.page|define.page} instead.
|
||||||
*/
|
*/
|
||||||
export const defineRoute = defineFn;
|
export const defineRoute = defineFn;
|
||||||
/**
|
/**
|
||||||
* @deprecated Use {@link [../mod.ts].Define.page|define.page} instead.
|
* @deprecated Use {@linkcode [./mod.ts].Define.page|define.page} instead.
|
||||||
*/
|
*/
|
||||||
export const defineLayout = defineFn;
|
export const defineLayout = defineFn;
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
// Compat with older Fresh versions
|
|
||||||
export {
|
|
||||||
type AppProps,
|
|
||||||
defineApp,
|
|
||||||
defineLayout,
|
|
||||||
defineRoute,
|
|
||||||
type ErrorPageProps,
|
|
||||||
type Handler,
|
|
||||||
type Handlers,
|
|
||||||
type LayoutProps,
|
|
||||||
type RouteContext,
|
|
||||||
type UnknownPageProps,
|
|
||||||
} from "./server.ts";
|
|
||||||
@@ -1,19 +1,9 @@
|
|||||||
import type { Handlers } from "fresh/compat";
|
import { define } from "../../utils/state.ts";
|
||||||
|
|
||||||
export const handler: Handlers<void> = {
|
export const handler = define.handlers({
|
||||||
GET(ctx) {
|
GET(ctx) {
|
||||||
const slug = ctx.params.slug;
|
return ctx.url.pathname === "/concepts/architechture"
|
||||||
|
? ctx.redirect("/docs/concepts/architecture")
|
||||||
if (slug === "concepts/architechture") {
|
: ctx.redirect("/docs/introduction");
|
||||||
return new Response("", {
|
|
||||||
status: 307,
|
|
||||||
headers: { location: "/docs/concepts/architecture" },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Response("", {
|
|
||||||
status: 307,
|
|
||||||
headers: { location: "/docs/introduction" },
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user