Last active
March 7, 2021 08:01
-
-
Save clonn/6005654 to your computer and use it in GitHub Desktop.
Node.js with Express, deploy through web hook.
this is route part code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var exec = require('child_process').exec; | |
var set = function (app) { | |
app.post('/deploy', function (req, res) { | |
var feedback; | |
var branch = 'master'; | |
try { | |
feedback = JSON.parse(req.body.payload); | |
console.log(feedback); | |
} catch (e) { | |
console.log('[STATUS] payload parse error'); | |
return res.send('[STATUS] payload parse error'); | |
} | |
if (feedback.ref.match('master')) { | |
exec('bash -x /path/install.sh', function (error, stdout, stderr) { | |
console.log('[STATUS] deploy server'); | |
console.log(error); | |
console.log(stdout); | |
console.log(stderr); | |
res.send('[STATUS] deploy server'); | |
}); | |
} else { | |
res.send('[STATUS] deploy server NOT in master branch'); | |
} | |
}); | |
}; | |
module.exports.set = set; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express') | |
, http = require('http') | |
, deploy = requre('./routeDeploy') | |
, path = require('path'); | |
var app = express(); | |
app.configure(function(){ | |
app.use(express.compress()); | |
app.set('port', process.env.PORT || 3000); | |
app.set('views', __dirname + '/views'); | |
app.set('view engine', 'ejs'); | |
app.use(express.logger('dev')); | |
app.use(express.bodyParser()); | |
app.use(express.methodOverride()); | |
app.use(express.cookieParser('your secret here')); | |
app.use(express.session()); | |
app.use(app.router); | |
app.use(require('stylus').middleware(__dirname + '/public')); | |
app.use(express.static(path.join(__dirname, 'public'))); | |
}); | |
app.configure('development', function(){ | |
app.use(express.errorHandler()); | |
}); | |
deploy.set(app); | |
http.createServer(app).listen(app.get('port'), function(){ | |
console.log("Express server listening on port " + app.get('port')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment