Created
December 2, 2018 13:10
-
-
Save PradalCyril/1e1e5764e95f35e6560362f606d9cd31 to your computer and use it in GitHub Desktop.
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
const http = require('http'); | |
const port = 3000; | |
const requestHandler = (request, response) => { | |
console.log(request.url); | |
server | |
if (request.url == '/') { | |
response.writeHead(200, { 'Content-type': 'text/htlm' }); | |
response.write('Bienvenue sur votre server!') | |
response.end(); | |
} else if (request.url == '/contact') { | |
response.writeHead(200, { 'Content-type': 'text/htlm' }) | |
response.end('Nous ne sommes pas joignable ') | |
} else if (request.url.startsWith("/display/")) { | |
response.write('Vous tentez d’afficher le profil de ' + request.url.substring(9, request.url.length)) | |
response.end(); | |
} | |
} | |
const server = http.createServer(requestHandler); | |
server.listen(port, (err) => { | |
if (err) { | |
throw new Error('Something bad happened...'); | |
} | |
console.log(`server is listening on ${port}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment