refactor: changed Handlers type to MultiHandler (#1360)
This commit is contained in:
@@ -16,7 +16,7 @@ interface Project {
|
||||
stars: number;
|
||||
}
|
||||
|
||||
export const handler: Handlers<Project> = {
|
||||
export const handler: MultiHandler<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`, `Handlers`, `Handler`, and
|
||||
The type parameter on the `PageProps`, `MultiHandler`, `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.
|
||||
|
||||
@@ -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 { Handlers, PageProps } from "$fresh/server.ts";
|
||||
import { MultiHandler, PageProps } from "$fresh/server.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
export const handler: MultiHandler = {
|
||||
async GET(req, ctx) {
|
||||
const blogpost = await fetchBlogpost(ctx.params.slug);
|
||||
if (!blogpost) {
|
||||
|
||||
@@ -20,9 +20,9 @@ submissions:
|
||||
|
||||
```tsx
|
||||
// routes/subscribe.tsx
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
import { MultiHandler } from "$fresh/server.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
export const handler: MultiHandler = {
|
||||
async GET(req, ctx) {
|
||||
return await ctx.render();
|
||||
},
|
||||
|
||||
@@ -33,7 +33,7 @@ export async function handler(
|
||||
|
||||
```ts
|
||||
// routes/myHandler.ts
|
||||
export const handler: Handlers<any, { data: string }> = {
|
||||
export const handler: MultiHandler<any, { data: string }> = {
|
||||
GET(_req, ctx) {
|
||||
return new Response(`middleware data is ${ctx.state.data}`);
|
||||
},
|
||||
|
||||
@@ -27,9 +27,9 @@ Let's look at a basic route that returns a plain text string:
|
||||
```tsx
|
||||
// routes/plain.tsx
|
||||
|
||||
import { HandlerContext, Handlers } from "$fresh/server.ts";
|
||||
import { HandlerContext, MultiHandler } from "$fresh/server.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
export const handler: MultiHandler = {
|
||||
GET(_req: Request, _ctx: HandlerContext) {
|
||||
return new Response("Hello World");
|
||||
},
|
||||
@@ -73,9 +73,9 @@ response after rendering the page component.
|
||||
```tsx
|
||||
// routes/html.tsx
|
||||
|
||||
import { HandlerContext, Handlers, PageProps } from "$fresh/server.ts";
|
||||
import { HandlerContext, MultiHandler, PageProps } from "$fresh/server.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
export const handler: MultiHandler = {
|
||||
async GET(_req: Request, ctx: HandlerContext) {
|
||||
const resp = await ctx.render();
|
||||
resp.headers.set("X-Custom-Header", "Hello World");
|
||||
|
||||
Reference in New Issue
Block a user