const http = require('http');
const port = 3000;
const requestHandler = (request, response) => {
console.log(request.url);
if (request.url === '/'){
response.end('Bienvenue sur vôtre serveur !!')
} else if (request.url === '/contact'){
response.end('Nous ne sommes pas joignables pour le moment !')
} else if (request.url.split('/').includes("display")){
const name = request.url.split('/');
response.end(`Vous tentez d'afficher le profil de ${name[name.length -1]}`)
} else {
response.end('error');
}
}
const server = http.createServer(requestHandler);
server.listen(port, (err) => {
if (err) {
throw new Error('Something bad happened...');
}
console.log(`server is listening on ${port}`);
});