Created
July 25, 2016 19:00
-
-
Save lexoyo/1d8e30aecd6c16ef7a54d26325eb2bef to your computer and use it in GitHub Desktop.
workshop nodejs by @silexlabs
This file contains hidden or 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 insultes = [ | |
'méchant', | |
'coco', | |
'bachibouzouk', | |
'débile' | |
]; | |
function insulteAleatoire(){ | |
return insultes[Math.floor | |
(Math.random()*4)]; | |
} | |
var insulte=insulteAleatoire() | |
+ ' de ' | |
+ insulteAleatoire(); | |
var prenom = process.argv[2]; | |
if (!prenom){ | |
throw "Donne ton prenom pauvre con"; | |
} | |
var output = prenom + ' est un ' + | |
insulte; | |
console.log(output); | |
var http = require('http'); | |
var serveur = http.createServer( | |
function repond(request, response){ | |
var noms = request.url.split('/') | |
.filter( function (nom){ | |
return nom != ''; | |
} ); | |
var dernier= noms.pop() | |
var toto= noms.join(', ') | |
var toutLeMOnde; | |
if(noms.length > 0 ){ | |
toutLeMOnde = toto+ ' et '+ dernier+ ' étaient des ' | |
} | |
else{ | |
toutLeMOnde=dernier + " était un " | |
} | |
response.write( | |
prenom | |
+ ' a dit que ' | |
+ toutLeMOnde | |
+ insulteAleatoire() | |
+ ( (noms.length>0) ? 's' : '' ) | |
); | |
response.end(); | |
} | |
); | |
serveur.listen(8000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment