-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
93 lines (85 loc) · 2.19 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
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
'use strict'
const cors = require('cors')
const morgan = require('morgan')
const compression = require('compression')
const serverless = require('serverless-http');
const bodyParser = require('body-parser')
const express = require('express')
const GithubWebHook = require('express-github-webhook')
const connect = require('./controller/connect')
const encrypt = require('./controller/encrypt')
const auth = require('./controller/auth')
const handlePR = require('./controller/handlePR')
const home = require('./controller/home')
const process = require('./controller/process')
const github = require('./controller/github')
const app = express()
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({
extended: true
}))
const corsOptions = {
origin: '*',
credentials: true,
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
preflightContinue: false,
optionsSuccessStatus: 204
};
app.use(cors(corsOptions))
const router = express.Router()
router.use(compression())
router.get(
'/v:version/connect/:username/:repository',
connect
)
router.post(
'/v:version/entry/:username/:repository/:branch',
process
)
router.post(
'/v:version/custom/:username/:repository/:branch/:property/:code',
github(process)
)
router.post(
'/v:version/entry/:username/:repository/:branch/:property',
process
)
router.post(
'/v:version/entry/:service/:username/:repository/:branch/:property',
process
)
router.get(
'/v:version/encrypt/:text',
encrypt
)
router.get(
'/v:version/auth/:service/:username/:repository/:branch/:property',
auth
)
router.get(
'/',
home
)
const webhookHandler = GithubWebHook({
path: '/v1/webhook'
})
webhookHandler.on('pull_request', handlePR)
app.use(webhookHandler)
const customLogger = (tokens, req, res) => {
const log = [
tokens.method(req, res),
tokens.url(req, res),
tokens.status(req, res),
tokens.res(req, res, 'content-length'), '-',
tokens['response-time'](req, res), 'ms'
].join(' ')
console.log(log)
return log
}
app.use(morgan(customLogger))
app.use('/.netlify/functions/server', router);
router.use(cors())
router.use(bodyParser.json())
router.use(bodyParser.urlencoded({ extended: true }))
module.exports = app;
module.exports.handler = serverless(app);