Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

middleware-context.ts

29 lines817 Bytes

1import { createFileRoute } from '@tanstack/solid-router'
2import { createMiddleware, json } from '@tanstack/solid-start'
3​
4const testParentMiddleware = createMiddleware().server(async ({ next }) => {
5 const result = await next({ context: { testParent: true } })
6 return result
7})
8​
9const testMiddleware = createMiddleware()
10 .middleware([testParentMiddleware])
11 .server(async ({ next }) => {
12 const result = await next({ context: { test: true } })
13 return result
14 })
15​
16export const Route = createFileRoute('/api/middleware-context')({
17 server: {
18 middleware: [testMiddleware],
19 handlers: {
20 GET: ({ request, context }) => {
21 return json({
22 url: request.url,
23 context: context,
24 expectedContext: { testParent: true, test: true },
25 })
26 },
27 },
28 },
29})