-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
59 lines (45 loc) · 1.42 KB
/
app.js
File metadata and controls
59 lines (45 loc) · 1.42 KB
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
/*
* @Description:
* @Author: Ethan Wong
* @Date: 2021-01-08 09:50:55
* @FilePath: \app.js
* @LastEditTime: 2021-01-08 17:33:23
* @LastEditors: your name
*/
var express = require('express');
var app = express();
var bodyParser = require('body-parser')
var process = require('child_process');
//parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
//parse application/json
app.use(bodyParser.json())
app.use('/public', express.static('public'));
app.get('/', function (req, res) {
res.send('<h1>auto-deploy-application</h1>');
})
app.post('/deploy', function (req, res) {
console.log("hostname="+req.hostname)
console.log("ip="+req.ip)
console.log("originalUrl="+req.originalUrl)
console.log("path="+req.path)
console.log("query="+JSON.stringify(req.query))
if(req.query.secret == "9b67b0c4756c46f0a96f94170159ac5b"){
var command = 'sh deploy.sh restart';
exec(command);
}
console.log(JSON.stringify(req.body));
res.send("ok");
})
function exec(command){
process.exec(command, function(error, stdout, stderr) {
console.log("error:"+error);
console.log("stdout:"+stdout);
console.log("stderr:"+stderr);
});
}
var server = app.listen(4000, function () {
var host = server.address().address
var port = server.address().port
console.log("应用实例,访问地址为 http://%s:%s", host, port)
})