-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
26 lines (22 loc) · 674 Bytes
/
Copy pathapp.js
File metadata and controls
26 lines (22 loc) · 674 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
'use strict';
const koa = require('koa');
const app = koa();
const view = require('./view/view');
const contr = require('./controller');
function isShellAgent(userAgentStr) {
return ['curl', 'wget', 'httpie', 'lwp-request']
.some(agent => userAgentStr.includes(agent));
}
contr.startUpdatingRates();
app.use(function *() {
const agent = this.request.header['user-agent'];
if (typeof agent === 'string' && isShellAgent(agent.toLowerCase())) {
this.type = 'text/plain; charset=utf-8';
this.body = yield view.text();
} else {
this.type = 'html';
this.body = yield view.html();
}
});
app.listen(52190);
console.log('Curls listening on 52190');