19 lines
600 B
TypeScript
19 lines
600 B
TypeScript
import RestResponse from "./RestResponse.ts";
|
|
import { Handler } from "./Router.ts";
|
|
|
|
export default function staticHandler(path: string): Handler {
|
|
return {
|
|
async handle(req) {
|
|
try {
|
|
const stream = await Deno.open(`${req.url}/${path}`);
|
|
const res: Uint8Array[] = [];
|
|
for await (const bit of stream.readable) res.push(bit);
|
|
stream.close();
|
|
return new RestResponse().body(new Blob(res).stream());
|
|
}
|
|
catch {
|
|
return undefined;
|
|
}
|
|
}
|
|
};
|
|
} |