fix: change MultiHandler back to Handlers (#1396)

This commit is contained in:
Marvin Hagemeister
2023-07-03 09:57:46 +02:00
committed by GitHub
parent eb53d53ab8
commit 16be99e69b
32 changed files with 135 additions and 66 deletions
+2 -2
View File
@@ -16,7 +16,7 @@ interface Project {
stars: number;
}
export const handler: MultiHandler<Project> = {
export const handler: Handlers<Project> = {
async GET(_req, ctx) {
const project = await db.projects.findOne({ id: ctx.params.id });
if (!project) {
@@ -36,7 +36,7 @@ export default function ProjectPage(props: PageProps<Project>) {
}
```
The type parameter on the `PageProps`, `MultiHandler`, `Handler`, and
The type parameter on the `PageProps`, `Handlers`, `Handler`, and
`HandlerContext` can be used to enforce a TypeScript type to use for the render
data. Fresh enforces during type checking that the types in all of these fields
are compatible within a single page.
+2 -2
View File
@@ -30,9 +30,9 @@ example when the route did match, but the requested resource does not exist.
This can be achieved with `ctx.renderNotFound`.
```tsx
import { MultiHandler, PageProps } from "$fresh/server.ts";
import { Handlers, PageProps } from "$fresh/server.ts";
export const handler: MultiHandler = {
export const handler: Handlers = {
async GET(req, ctx) {
const blogpost = await fetchBlogpost(ctx.params.slug);
if (!blogpost) {
+2 -2
View File
@@ -20,9 +20,9 @@ submissions:
```tsx
// routes/subscribe.tsx
import { MultiHandler } from "$fresh/server.ts";
import { Handlers } from "$fresh/server.ts";
export const handler: MultiHandler = {
export const handler: Handlers = {
async GET(req, ctx) {
return await ctx.render();
},
+3 -6
View File
@@ -12,7 +12,7 @@ Each middleware gets passed a `next` function in the context argument that is
used to trigger child handlers. The `ctx` also has a `state` property that can
be used to pass arbitrary data to downstream (or upstream) handlers. This
`state` is included in `PageProps` by default, which is available to both the
special [_app](/docs/concepts/app-wrapper.md) wrapper and normal
special [\_app](/docs/concepts/app-wrapper.md) wrapper and normal
[routes](/docs/concepts/routes.md).
```ts
@@ -36,7 +36,7 @@ export async function handler(
```ts
// routes/myHandler.ts
export const handler: MultiHandler<any, { data: string }> = {
export const handler: Handlers<any, { data: string }> = {
GET(_req, ctx) {
return new Response(`middleware data is ${ctx.state.data}`);
},
@@ -125,10 +125,7 @@ create a `_middleware.ts` file in the `routes` folder like this:
```ts
import { MiddlewareHandlerContext } from "$fresh/server.ts";
export async function handler(
req: Request,
ctx: MiddlewareHandlerContext,
) {
export async function handler(req: Request, ctx: MiddlewareHandlerContext) {
console.log(ctx.destination);
console.log(req.url);
const resp = await ctx.next();
+4 -4
View File
@@ -28,9 +28,9 @@ Let's look at a basic route that returns a plain text string:
```tsx
// routes/plain.tsx
import { HandlerContext, MultiHandler } from "$fresh/server.ts";
import { HandlerContext, Handlers } from "$fresh/server.ts";
export const handler: MultiHandler = {
export const handler: Handlers = {
GET(_req: Request, _ctx: HandlerContext) {
return new Response("Hello World");
},
@@ -74,9 +74,9 @@ response after rendering the page component.
```tsx
// routes/html.tsx
import { HandlerContext, MultiHandler, PageProps } from "$fresh/server.ts";
import { HandlerContext, Handlers, PageProps } from "$fresh/server.ts";
export const handler: MultiHandler = {
export const handler: Handlers = {
async GET(_req: Request, ctx: HandlerContext) {
const resp = await ctx.render();
resp.headers.set("X-Custom-Header", "Hello World");