Download apps/readest-app/src/middleware.ts from echodict/readest: direct link, hf CLI and curl.
- Browser
- Download file 1.23 kB
-
https://huggingface.co/datasets/echodict/readest/resolve/main/apps/readest-app/src/middleware.ts
- Command line
-
hf download hf://datasets/echodict/readest/apps/readest-app/src/middleware.ts
-
curl -L -o middleware.ts https://huggingface.co/datasets/echodict/readest/resolve/main/apps/readest-app/src/middleware.ts
1.23 kB
| import { NextRequest, NextResponse } from 'next/server'; | |
| const allowedOrigins = [ | |
| 'https://web.readest.com', | |
| 'https://tauri.localhost', | |
| 'http://tauri.localhost', | |
| 'http://localhost:3000', | |
| 'http://localhost:3001', | |
| 'tauri://localhost', | |
| ]; | |
| const corsOptions = { | |
| 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', | |
| 'Access-Control-Allow-Headers': '*', | |
| 'Access-Control-Max-Age': '86400', | |
| }; | |
| export function middleware(request: NextRequest) { | |
| const origin = request.headers.get('origin') ?? ''; | |
| const isAllowedOrigin = allowedOrigins.includes(origin); | |
| if (request.method === 'OPTIONS') { | |
| const preflightHeaders = new Headers({ | |
| ...corsOptions, | |
| ...(isAllowedOrigin && { 'Access-Control-Allow-Origin': origin }), | |
| }); | |
| return new NextResponse(null, { | |
| status: 200, | |
| headers: preflightHeaders, | |
| }); | |
| } | |
| const response = NextResponse.next(); | |
| if (isAllowedOrigin) { | |
| response.headers.set('Access-Control-Allow-Origin', origin); | |
| } | |
| Object.entries(corsOptions).forEach(([key, value]) => { | |
| response.headers.set(key, value); | |
| }); | |
| return response; | |
| } | |
| export const config = { | |
| matcher: ['/api/:path*', '/api/stripe/:path*', '/api/metadata/:path*'], | |
| }; | |