-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.ts
36 lines (32 loc) · 961 Bytes
/
mod.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
;(function (Deno, { mode }) {
const EXTENSIONS = {
json: 'application/json; charset=utf-8',
'': 'text/html',
html: 'text/html',
ico: 'ico',
}
Deno.serve(async (req) => {
const url = new URL(req.url)
const extension = [...url.pathname].join('').split('.')[1]
// TODO: add error handling
const text = await Deno.readTextFile('.' + url.pathname)
if (mode === 'debug') {]
console.log('Method:', req.method)
console.log('Path:', url.pathname)
console.log('Exntension:', extension)
console.log('Query parameters:', url.searchParams)
console.log('Headers:', req.headers)
console.log('File contents"', text)
if (req.body) {
const body = await req.text()
console.log('Body:', body)
}
}
return new Response(text, {
status: 200,
headers: {
'content-type': EXTENSIONS[extension] || '',
},
})
})
})(Deno, { mode: 'debug' })