-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathserver.js
43 lines (40 loc) · 1.47 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
var express = require('express')
var GithubWebHook = require('express-github-webhook')
var webhookHandler = GithubWebHook({ path: '/webhook', secret: '123456' })
var shell = require('shelljs')
var bodyParser = require('body-parser')
// var history = require('connect-history-api-fallback');
// 开启gzip压缩,如果你想关闭gzip,注释掉下面两行代码,重新执行`node server.js`
var compression = require('compression')
var app = express()
app.use(compression())
app.use(bodyParser.json())
app.use(webhookHandler)
// app.use(history());
// var webhook = require('./webhook.js')
app.use(express.static(__dirname + '/dist'))
// app.post('/webhook', webhook);
webhookHandler.on('push', function(err, req, res) {
shell.exec('git fetch --all')
if (shell.exec('npm run build').code !== 0) {
// 执行npm run build 命令
shell.echo('Error: Git commit failed')
shell.exit(1)
}
shell.exec('pm2 startOrRestart ecosystem.config.js --env production')
res.send({ result: 'git fetch --all' })
})
webhookHandler.on('error', function(err, req, res) {
console.log(err)
})
// var proxy = require('http-proxy-middleware')
// var options = {
// target: 'http://192.168.2.243:7070', // 测试
// changeOrigin: true, // 需要虚拟主机站点
// pathRewrite: {
// // '^/ns-index': ''
// }
// }
// var exampleProxy = proxy(options) //开启代理功能,并加载配置
// app.use('/ns-index', exampleProxy) //对地址为’/‘的请求全部转发
app.listen(8888)