Created
July 26, 2013 19:40
-
-
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.
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 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