-
Notifications
You must be signed in to change notification settings - Fork 0
/
website.ts
36 lines (30 loc) · 1010 Bytes
/
website.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
import { listenAndServe } from "https://deno.land/std@0.111.0/http/server.ts";
async function handleRequest(request: Request): Promise<Response> {
const { pathname } = new URL(request.url);
// This is how the server works:
// 1. A request comes in for a specific asset.
// 2. We read the asset from the file system.
// 3. We send the asset back to the client.
// Check if the request is for style.css.
if (pathname.startsWith("/style.css")) {
// Read the style.css file from the file system.
const file = await Deno.readFile("./style.css");
// Respond to the request with the style.css file.
return new Response(file, {
headers: {
"content-type": "text/css",
},
});
}
const file = await Deno.readFile("./index.html");
return new Response(
file,
{
headers: {
"content-type": "text/html; charset=utf-8",
},
},
);
}
console.log("Listening on http://localhost:8080");
await listenAndServe(":8080", handleRequest);