Created
December 28, 2012 05:01
-
-
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
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 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