-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStaticFile.ts
More file actions
35 lines (19 loc) · 744 Bytes
/
StaticFile.ts
File metadata and controls
35 lines (19 loc) · 744 Bytes
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
import {Router} from "./Router.ts";
export class StaticFile {
private static Router = new Router()
public static serve(path: string) {
StaticFile.Router.get(path, async function (req){
const mainFolder = req.params?.main
const subFolder = req.params?.sub;
const filename = req.params?.filename
let readFile;
if (subFolder == null) readFile = await Deno.readFile(`${mainFolder}/${filename}`);
readFile = await Deno.readFile(`${mainFolder}/${subFolder}/${filename}`);
return new Response(readFile, {
headers: {
'content-type': 'image/png',
}
})
})
}
}