forked from ccc112a/ws112a
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hw2.js
56 lines (51 loc) · 1.39 KB
/
hw2.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { Application, Router } from "https://deno.land/x/oak/mod.ts";
const books = new Map();
const classrooms = new Map();
classrooms.set("e320", {
id: "e320",
class: "Multimedia Classroom",
});
classrooms.set("e319", {
id: "e319",
class: "Embedded Systems Lab",
});
const router = new Router();
router
.get("/", (context) => {
context.response.body = "Hello world!";
})
.get("/nqu", (context) => {
context.response.body = `
<html>
<body>
<a href="https://www.nqu.edu.tw/">National Quemoy University</a>
</body>
</html>`
})
.get("/nqu/csie", (context) => {
context.response.body = `
<html>
<body>
<a href="https://csie.nqu.edu.tw/">Computer Science And information Engineering Department</a>
</body>
</html>`
})
.get("/to/nqu", (context) => {
context.response.redirect('https://www.nqu.edu.tw/')
})
.get("/to/nqu/csie", (context) => {
context.response.redirect('https://csie.nqu.edu.tw/')
})
.get("/room", (context) => {
context.response.body = Array.from(classrooms.values());
})
.get("/room/:id", (context) => {
if (context.params && context.params.id && classrooms.has(context.params.id)) {
context.response.body = classrooms.get(context.params.id);
}
});
const app = new Application();
app.use(router.routes());
app.use(router.allowedMethods());
console.log('start at : http://127.0.0.1:8000')
await app.listen({ port: 8000 });