Skip to content

Instantly share code, notes, and snippets.

@coderarity
Created December 28, 2012 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coderarity/4394690 to your computer and use it in GitHub Desktop.
Save coderarity/4394690 to your computer and use it in GitHub Desktop.
simple example of how to update Nodejitsu domains field without adding it to your package.json
var http = require('http')
var nj = require('nodejitsu-api')
var client = nj.createClient({
username: 'coderarity',
password: '*****',
remoteUri: 'https://api.nodejitsu.com'
})
var appname = 'dns-test'
var domains = []
var server = http.createServer(function (req, res) {
if (req.url === '/') {
res.writeHead(200, {'content-type': 'text/html'})
res.end('Welcome to IT WORKS!')
}
else if (req.url === '/domain') {
var buffer = ''
req.on('data', function (chunk) {
if (chunk !== undefined && chunk !== null)
buffer += chunk.toString()
})
req.on('end', function () {
domains.push(buffer)
// send request to add domain from buffer
client.apps.update(appname, {domains: domains}, function (err, result) {
if (err) {
res.writeHead(500)
res.end('update failed: '+err.message)
}
res.writeHead(200)
res.end('updated successfully! '+JSON.stringify(result))
})
})
}
else {
res.writeHead(404)
res.end('not found')
}
})
server.listen(8080)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment