Skip to content

Instantly share code, notes, and snippets.

@edivandecastro
Created July 26, 2013 19:40
Show Gist options
  • Save edivandecastro/6091683 to your computer and use it in GitHub Desktop.
Save edivandecastro/6091683 to your computer and use it in GitHub Desktop.
Estudo do node.js no site http://udgwebdev.com/node-js-para-leigos-trabalhando-com-http/ Recuperando a URL da requisição http.
var http = require('http');
var server = http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/html", "encoding" : "utf8"});
if(request.url == "/") {
response.write("<html><body><h1>Olá Node.js</h1>");
response.write("<a href='/bemvindo'>Bem Vindo!</a>");
response.write("</body><html>");
} else if(request.url == "/bemvindo") {
response.write("<html><body><h1>Bem vindo ao Node.js</h1>");
response.write("<a href='/'>Olá Node.js</a>");
response.write("</body><html>");
} else {
response.write("<html><body><h1>Página não encontrada!</h1>");
response.write("<a href='/'>Voltar ao início</a>");
response.write("</body><html>");
}
response.end();
});
server.listen(3000, function(){
console.log('Executando Servidor HTTP');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment