-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7705f88
commit 6cef200
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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' }) |