docs: Remove references to deprecated types (#2125)

As per the [1.6
release](https://deno.com/blog/fresh-1.6#simplified-typings), and
commentary by @csvn
[here](https://github.com/denoland/fresh/issues/2108#issuecomment-1836625789),
this PR aims to replace the references to deprecated typing in the
documentation.

Please see inline commentary for parts I'm unclear on.
This commit is contained in:
Christos Hrousis
2023-12-02 11:14:37 +00:00
committed by GitHub
parent 6eccdcf1a1
commit f3578f863f
10 changed files with 44 additions and 41 deletions
+4 -4
View File
@@ -16,9 +16,9 @@ requests. You can CORS enable all the routes affected by some `middleware` by
doing the following:
```ts routes/_middleware.ts
import { MiddlewareHandlerContext } from "$fresh/server.ts";
import { FreshContext } from "$fresh/server.ts";
export async function handler(req: Request, ctx: MiddlewareHandlerContext) {
export async function handler(req: Request, ctx: FreshContext) {
const origin = req.headers.get("Origin") || "*";
const resp = await ctx.next();
const headers = resp.headers;
@@ -45,9 +45,9 @@ deal with "preflight requests". Let's imagine you're trying to support a
`DELETE` route. Then you'd need to do something like this:
```ts routes/_middleware.ts
import { MiddlewareHandlerContext } from "$fresh/server.ts";
import { FreshContext } from "$fresh/server.ts";
export async function handler(_req: Request, ctx: MiddlewareHandlerContext) {
export async function handler(_req: Request, ctx: FreshContext) {
if (_req.method == "OPTIONS") {
const resp = new Response(null, {
status: 204,
@@ -17,10 +17,10 @@ Let's look at the example from the routing page more closely. We'll flesh out
the handler so that we end up with something like the following:
```ts routes/x.tsx
import { HandlerContext, RouteConfig } from "$fresh/server.ts";
import { FreshContext, RouteConfig } from "$fresh/server.ts";
export const handler = {
GET(_req: Request, { params }: HandlerContext) {
GET(_req: Request, { params }: FreshContext) {
console.log(params);
return new Response(params.path);
},
@@ -48,10 +48,10 @@ show the following:
Let's look at something a bit more complex:
```ts routes/api.tsx
import { HandlerContext, RouteConfig } from "$fresh/server.ts";
import { FreshContext, RouteConfig } from "$fresh/server.ts";
export const handler = {
GET(_req: Request, { params }: HandlerContext) {
GET(_req: Request, { params }: FreshContext) {
console.log(params);
return new Response(params.path);
},
+2 -2
View File
@@ -35,7 +35,7 @@ export default defineConfig({
But what's going on in this new `_middleware.ts` we've created?
```ts routes/_middleware.ts
import { MiddlewareHandlerContext } from "$fresh/server.ts";
import { FreshContext } from "$fresh/server.ts";
export interface State {
context: Context;
@@ -64,7 +64,7 @@ export class Context {
export async function handler(
_req: Request,
ctx: MiddlewareHandlerContext<State>,
ctx: FreshContext<State>,
) {
ctx.state.context = Context.instance();
if (ctx.destination === "route") {
+2 -2
View File
@@ -324,10 +324,10 @@ export const config: RouteConfig = {
```
```ts routes/reportHandler.ts
import { HandlerContext } from "$fresh/server.ts";
import { FreshContext } from "$fresh/server.ts";
export const handler = {
async POST(req: Request, _ctx: HandlerContext) {
async POST(req: Request, _ctx: FreshContext) {
const body = await req.json();
const report = JSON.stringify(body, null, 2);