deno.land / x / lume@v2.1.4 / middlewares / serve_folder.ts

serve_folder.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { serveFile } from "../core/server.ts";
import type { Middleware, RequestHandler } from "../core/server.ts";
/** The options to configure the middleware server */export interface Options { /** The root path */ root: string;
/** Serve the file as a fallback of the main middleware */ after?: boolean;}
export default function serveFolder(options: Options): Middleware { return async function ( request: Request, next: RequestHandler, ): Promise<Response> { let mainResponse: Response | undefined;
if (options.after) { mainResponse = await next(request);
if (mainResponse.status < 400) { return mainResponse; } }
const altResponse = await serveFile(options.root, request);
if (altResponse.status < 400) { return altResponse; }
return mainResponse || next(request); };}
lume

Version Info

Tagged at
7 months ago