forked from sheershoff/keymetrics-phabricator-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (34 loc) · 1.03 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
'use strict';
// checking requirements
var notEmptyEnvs = [
'KPG_TOKEN_VALUE',
'KPG_CONDUIT_TOKEN',
'KPG_CONDUIT_ROOT',
'KPG_PROJECT'
];
notEmptyEnvs.map(function(i){
if (!process.env[i]) {
throw new Error('Environment variable ' + i + ' should be set and not empty');
}
});
const express = require('express'),
bodyParser = require('body-parser'),
errorhandler = require('errorhandler'),
pmx = require('pmx'),
logger = require('morgan');
var logat = require('logat');
logat.setOptions(process.env.NODE_ENV === 'production'?{debug: false}:{});
var app = express();
// all environments
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
// app code
app.use(require('./middlewares/authorizer.js'));
app.use('/' + (process.env.KPG_PATH || ''), require('./routes/keymetricsHook.js'));
// development only
if (process.env.NODE_ENV !== 'production') {
logat.info(' *** USING DEVELOPMENT *** ');
app.use(errorhandler());
}
module.exports = app;