forked from ccc112a/ws112a
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HW2.js
59 lines (55 loc) · 1.43 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
57
58
59
import { Application, Router } from "https://deno.land/x/oak/mod.ts";
const room = new Map();
room.set("e319", {
教室: "e319",
功能: "數位系統應用實驗室",
});
room.set("e320", {
教室: "e320",
功能: "多媒體實驗室",
});
room.set("e321", {
教室: "e321",
功能: "電腦網路實驗室",
});
room.set("e322", {
教室: "e322",
功能: "嵌入式實驗室",
});
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/">金門大學首頁</a>
</body>
</html>`;
})
.get("/nqu/csie", (context) => {
context.response.body = `
<html>
<body>
<a href="https://csie.nqu.edu.tw/">金門大學資訊工程學系</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/:id", (context) => {
if (context.params && context.params.id && room.has(context.params.id)) {
context.response.body = room.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 });