Skip to content

Instantly share code, notes, and snippets.

@carlosvillu
Created November 6, 2014 10:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosvillu/6c42b46c27c454714be0 to your computer and use it in GitHub Desktop.
Save carlosvillu/6c42b46c27c454714be0 to your computer and use it in GitHub Desktop.
Poc server
var http = require('http'),
ipReg = /\api\/v1\/ip\/(\w+)/,
iplookup = require( './lib/iplookup' );
http.createServer(function (req, res) {
var ip = req.url.match( ipReg );
if( !ip )
{
res.writeHead(404, {'Content-Type': 'text/html'});
res.end( 'Not found' );
}
else
{
res.writeHead(200, {'Content-Type': 'text/json'});
res.end( '{"country": "' + iplookup( ip[1] ) + '"}' );
}
}).listen( 1337 );
console.log('Server running at http://127.0.0.1:1337/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment