-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
42 lines (36 loc) · 953 Bytes
/
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
// import dependencies
require('dotenv').config();
const Koa = require('koa');
const logger = require('koa-logger');
const router = require('./router/routes');
const cache = require('koa-response-cache');
// instantiate class
const app = new Koa();
// set environment variables
const PORT = process.env.PORT || 4000;
let REDIS_HOST;
let REDIS_PORT;
if (process.env.DEPLOYMENT === 'local') {
REDIS_HOST = process.env.REDIS_HOST;
REDIS_PORT = process.env.REDIS_PORT;
} else {
REDIS_PORT = process.env.REDIS_URL.split(':')[3];
REDIS_HOST = `${process.env.REDIS_URL.split(':')[0]}:${process.env.REDIS_URL.split(':')[2]}`;
}
// set redis options
const options = {
expire: 1000000,
routes: ['/api/(.*)'],
redis: {
host: REDIS_HOST,
port: REDIS_PORT,
},
};
// run app
app
// .use(logger())
.use(cache(options))
.use(router.routes())
.use(router.allowedMethods());
const server = app.listen(PORT);
module.exports = server;