-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
31 lines (26 loc) · 799 Bytes
/
index.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
var app = module.exports = require("koa")();
var html =
`<html>
<head>
<meta charset="UTF-8">
<title>A small test page</title>
<script src="//localhost:9091"></script>
</head>
<body>
Page loaded at: <span id="demo"></span>
</body>
<script language="javascript">
document.getElementById('demo').innerHTML = new Date();
</script>
</html>`;
app.use(function *(){
if(this.request.path === "/client"){
this.body = html;
return;
}
this.body = "Koa says Hi!";
});
var port = process.env.PORT || (process.argv[2] || 3000);
port = (typeof port != "number") ? port : 3000;
if(!module.parent){ app.listen(port); }
console.log("Application started. Listening on port:" + port);