Created
November 6, 2014 10:21
-
-
Save carlosvillu/6c42b46c27c454714be0 to your computer and use it in GitHub Desktop.
Poc server
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'), | |
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