www: new fenced code block design (#1629)

This commit is contained in:
Marvin Hagemeister
2023-08-13 10:52:41 +02:00
committed by GitHub
parent 7679e278cc
commit 6a599dbed5
43 changed files with 363 additions and 342 deletions
+8 -12
View File
@@ -15,8 +15,7 @@ be used to pass arbitrary data to downstream (or upstream) handlers. This
special [\_app](/docs/concepts/app-wrapper.md) wrapper and normal
[routes](/docs/concepts/routes.md).
```ts
// routes/_middleware.ts
```ts routes/_middleware.ts
import { MiddlewareHandlerContext } from "$fresh/server.ts";
interface State {
@@ -25,7 +24,7 @@ interface State {
export async function handler(
req: Request,
ctx: MiddlewareHandlerContext<State>,
ctx: MiddlewareHandlerContext<State>
) {
ctx.state.data = "myData";
const resp = await ctx.next();
@@ -34,8 +33,7 @@ export async function handler(
}
```
```ts
// routes/myHandler.ts
```ts routes/myHandler.ts
export const handler: Handlers<any, { data: string }> = {
GET(_req, ctx) {
return new Response(`middleware data is ${ctx.state.data}`);
@@ -50,7 +48,7 @@ specific first).
For example, take a project with the following routes:
```
```txt Project Structure
└── routes
   ├── _middleware.ts
   ├── index.ts
@@ -83,9 +81,7 @@ A single middleware file can also define multiple middlewares (all for the same
route) by exporting an array of handlers instead of a single handler. For
example:
```ts
// routes/_middleware.ts
```ts routes/_middleware.ts
export const handler = [
async function middleware1(req, ctx) {
// do something
@@ -101,7 +97,7 @@ export const handler = [
It should be noted that `middleware` has access to route parameters. If you're
running a fictitious `routes/[tenant]/admin/_middleware.ts` like this:
```ts
```ts routes/[tenant]/admin/_middleware.ts
import { MiddlewareHandlerContext } from "$fresh/server.ts";
export async function handler(_req: Request, ctx: MiddlewareHandlerContext) {
@@ -146,7 +142,7 @@ for a `route`, as opposed to something like `http://localhost:8001/favicon.ico`.
Initiate a new Fresh project (`deno run -A -r https://fresh.deno.dev/`) and then
create a `_middleware.ts` file in the `routes` folder like this:
```ts
```ts routes/_middleware.ts
import { MiddlewareHandlerContext } from "$fresh/server.ts";
export async function handler(req: Request, ctx: MiddlewareHandlerContext) {
@@ -159,7 +155,7 @@ export async function handler(req: Request, ctx: MiddlewareHandlerContext) {
If you start up your server (`deno task start`) you'll see the following:
```
```sh Terminal
Task start deno run -A --watch=static/,routes/ dev.ts
Watcher Process started.
The manifest has been generated for 4 routes and 1 islands.