-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathpublish.js
More file actions
68 lines (59 loc) · 1.92 KB
/
Copy pathpublish.js
File metadata and controls
68 lines (59 loc) · 1.92 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
60
61
62
63
64
65
66
67
68
var zipFolder = require('zip-folder');
var path = require('path');
var fs = require('fs');
var request = require('request');
// We are using your web app name in various places,
// so please change it here!!!
var myWebAppName = "jannennodeapp";
// These are for creating the zip file to upload. No need to change.
var rootFolder = path.resolve('.');
var zipPath = path.resolve(rootFolder, '../'+myWebAppName+'.zip');
// We are using Kudu to publish the created zip to Azure.
// This is URL points to your application kudu zip publishing api.
var kuduApi = 'https://'+myWebAppName+'.scm.azurewebsites.net/api/zip/site/wwwroot';
// You'll get the deployment password from your Web App at Azure portal.
// Go to App Service - Overview, then hit the button on top bar saying "Get publish profile"
// The resulting file contains publishProfile sections. Pick the
// (usually first) section, where profile name contains "Web Deploy".
var userName = '$'+myWebAppName;
// Paste the key here to replace the xxxxxxx's!
var userPWD = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
function uploadZip(callback) {
fs.createReadStream(zipPath).pipe(request.put(kuduApi, {
auth: {
username: userName,
password: userPWD,
sendImmediately: true
},
headers: {
"Content-Type": "applicaton/zip"
}
}))
.on('response', function(resp){
if (resp.statusCode >= 200 && resp.statusCode < 300) {
fs.unlink(zipPath,(err) => {});
callback(null);
} else if (resp.statusCode >= 400) {
callback(resp);
}
})
.on('error', function(err) {
callback(err)
});
}
function publish(callback) {
zipFolder(rootFolder, zipPath, function(err) {
if (!err) {
uploadZip(callback);
} else {
callback(err);
}
})
}
publish(function(err) {
if (!err) {
console.log(myWebAppName+' succesfully published!');
} else {
console.error('failed to publish '+myWebAppName, err);
}
});