-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
35 lines (29 loc) · 830 Bytes
/
server.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
"use strict";
const koa = require("koa");
const Router = require("koa-router");
const views = require("koa-views");
const request = require("request");
let app = koa();
let router = new Router();
process.on("uncaughtException", (err) => {
console.error(err)
})
let templateRenderTest = function *(){
let step = new Promise(function(resolve, reject) {
request("http://httpbin.org/status/202", (err, res, body) => {
resolve(res)
});
});
let result = yield step
yield this.render("index", {
"response_from_google": result.statusCode,
"current_time": new Date(),
"random_number": Math.random()
})
}
router.get("/test", templateRenderTest);
app.use(views(`${__dirname}/views`, {
map: { html: "twig" }
}))
app.use(router.routes());
app.listen(3000);