forked from koajs/api-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
68 lines (47 loc) · 1.01 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* Module dependencies.
*/
var responseTime = require('koa-response-time');
//var ratelimit = require('koa-ratelimit');
var compress = require('koa-compress');
var logger = require('koa-logger');
var router = require('koa-router');
var load = require('./lib/load');
//var redis = require('redis');
var koa = require('koa');
/**
* Environment.
*/
var env = process.env.NODE_ENV || 'development';
/**
* Expose `api()`.
*/
module.exports = api;
/**
* Initialize an app with the given `opts`.
*
* @param {Object} opts
* @return {Application}
* @api public
*/
function api(opts) {
opts = opts || {};
var app = koa();
// logging
if ('test' != env) app.use(logger());
// x-response-time
app.use(responseTime());
// compression
app.use(compress());
// rate limiting
//app.use(ratelimit({
// max: opts.ratelimit,
// duration: opts.duration,
// db: redis.createClient()
//}));
// routing
app.use(router(app));
// boot
load(app, __dirname + '/api');
return app;
}