-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroutes.js
More file actions
28 lines (25 loc) · 705 Bytes
/
Copy pathroutes.js
File metadata and controls
28 lines (25 loc) · 705 Bytes
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
const fs = require('fs');
const path = require('path');
const router = require('koa-router')();
router.get('/earth', indexView);
function chooseFile(url){
return (url) => {
var html = yield readFileThunk(path.join(__dirname, url));
this.body = html;
}
}
var readFileThunk = function(src) {
return new Promise(function(resolve, reject) {
fs.readFile(src, {
'encoding': 'utf8'
}, function(err, data) {
if (err) return reject(err);
resolve(data);
});
});
}
function* indexView(next) {
var html = yield readFileThunk(path.join(__dirname, '/earth/index.html'));
this.body = html;
}
module.exports = router;