-
Notifications
You must be signed in to change notification settings - Fork 9
/
server.js
39 lines (39 loc) · 1.02 KB
/
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
36
37
38
39
var serve = require('koa-static');
var cwd = process.cwd();
var path = require('path');
var app = require('koa')();
var fs = require('fs');
var root = cwd;
var serveIndex = require('koa-serve-index');
var koaBody = require('koa-body');
var jscoverHandler = require('koa-node-jscover');
var jscoverCoveralls = require('node-jscover-coveralls/lib/koa');
var comboHandler = require('combo-handler/lib/koa');
app.use(comboHandler());
app.use(function *(next) {
if (path.extname(this.path) === '.jss') {
var func = require(path.resolve(__dirname, this.path.substring(1))).call(this);
yield *func;
} else {
yield *next;
}
});
// parse application/x-www-form-urlencoded
app.use(koaBody());
app.use(jscoverHandler({
jscover: require('node-jscover'),
next: function () {
return 1;
}
}));
app.use(jscoverCoveralls());
app.use(serveIndex(root, {
hidden: true,
view: 'details'
}));
app.use(serve(root, {
hidden: true
}));
var port = process.env.npm_package_config_port;
app.listen(port);
console.log('server start at ' + port);