0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00
verdaccio/lib/notify.js

48 lines
1 KiB
JavaScript
Raw Normal View History

var Handlebars = require('handlebars')
var request = require('request')
var handleNotify = function(metadata, notifyEntry) {
var regex
if(metadata.name && notifyEntry.packagePattern) {
regex = new RegExp(notifyEntry.packagePattern, notifyEntry.packagePatternFlags || '')
if(!regex.test(metadata.name)) {
return
}
}
var template = Handlebars.compile(notifyEntry.content)
var content = template( metadata )
var options = {
body: content
}
if ( notifyEntry.headers ) {
options.headers = notifyEntry.headers
}
options.method = notifyEntry.method
if(notifyEntry.endpoint) {
options.url = notifyEntry.endpoint
}
request(options)
}
module.exports.notify = function(metadata, config) {
if (config.notify) {
if(config.notify.content) {
handleNotify(metadata, config.notify)
}
else {
for(var key in config.notify) {
if(config.notify.hasOwnProperty(key)) {
handleNotify(metadata, config.notify[key])
}
}
}
}
}