-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
216 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
necesario instalar los modulos express y replacestream | ||
npm install express | ||
npm install replacestream | ||
*/ | ||
|
||
var express = require('express'); | ||
var path = require('path'); | ||
var app = express(); | ||
var fs = require("fs"); | ||
var replaceStream = require('replacestream'); | ||
var bodyParser = require('body-parser'); | ||
var QS = require('querystring'), | ||
e, d; | ||
|
||
app.use(bodyParser.urlencoded({ | ||
extend: true | ||
})); | ||
app.use(express.static(path.join(__dirname, 'public'))); | ||
|
||
app.post('/respuesta', function (req, res) { | ||
var respuesta = ""; | ||
var salida = ""; | ||
if (req.body.pregunta == 1) { | ||
respuesta = req.body.america; | ||
respuesta = respuesta.toLowerCase(); | ||
if (respuesta == "cristobal colon" || respuesta == "cristobal colón") { | ||
salida = "Respuesta Correcta!!"; | ||
} else { | ||
salida = "Respuesta Incorrecta. Respuesta correcta: Critobal Colón"; | ||
} | ||
} else { | ||
if (req.body.pregunta == 2) { | ||
respuesta = req.body.portugal; | ||
respuesta = respuesta.toLowerCase(); | ||
if (respuesta == "lisboa") { | ||
salida = "Respuesta Correcta!!"; | ||
} else { | ||
salida = "Respuesta Incorrecta. Respuesta correcta: Lisboa"; | ||
} | ||
} else { | ||
salida = "no se ha enviado nada"; | ||
} | ||
} | ||
res.writeHead(200, { | ||
'Content-Type': 'text/html' | ||
}); | ||
fs.createReadStream('public/html/respuesta.html') | ||
.pipe(replaceStream('{{valor}}', salida)) | ||
.pipe(res); | ||
}); | ||
|
||
app.get('/preguntas', function (req, res) { | ||
res.writeHead(200, { | ||
'Content-Type': 'text/html' | ||
}); | ||
fs.createReadStream('public/index.html').pipe(res); | ||
}); | ||
|
||
|
||
app.listen(8000); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
*{ | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
header { | ||
width: 100%; | ||
height: 75px; | ||
margin: 0 auto; | ||
text-align: center; | ||
background-color: bisque; | ||
} | ||
|
||
.header { | ||
width: 300px; | ||
font-size: 1.5em; | ||
line-height: 75px; | ||
|
||
margin: 0 auto; | ||
text-align: center; | ||
} | ||
|
||
.content { | ||
width: 90%; | ||
margin: 0 auto; | ||
margin-top: 50px; | ||
margin-bottom: 50px; | ||
} | ||
|
||
footer { | ||
|
||
width: 100%; | ||
height: 100px; | ||
margin: 0 auto; | ||
/*margin-top: 100px;*/ | ||
text-align: center; | ||
background-color: dimgray; | ||
color: white; | ||
} | ||
|
||
footer .content{ | ||
|
||
width: 300px; | ||
font-size: 1.5em; | ||
line-height: 100px; | ||
|
||
margin: 0 auto; | ||
text-align: center; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!doctype html> | ||
<html lang="es"> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Node.js</title> | ||
<link rel="stylesheet" href="./css/estilos.css"> | ||
</head> | ||
|
||
<body> | ||
<header> | ||
<div class="header"> | ||
Ejercicio P2P Módulo 4 | ||
</div> | ||
</header> | ||
|
||
|
||
<div class="content"> | ||
<h3>Respuesta</h3> | ||
|
||
<br/> | ||
{{valor}} | ||
<br/> | ||
<a href="../index.html">Volver</a> | ||
</div> | ||
|
||
<footer> | ||
<div class="content"> | ||
Curso Node.js | ||
</div> | ||
</footer> | ||
|
||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<!doctype html> | ||
<html lang="es"> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Node.js</title> | ||
<link rel="stylesheet" href="./css/estilos.css"> | ||
</head> | ||
|
||
<body> | ||
<header> | ||
<div class="header"> | ||
Ejercicio P2P Módulo 4 | ||
</div> | ||
</header> | ||
|
||
|
||
<div class="content"> | ||
<h3>Responde a una de las dos preguntas</h3> | ||
<br/> | ||
<form method="post" action="respuesta" id="enviar1"> | ||
<label for="america"> | ||
¿Quién descubrio América? | ||
</label> | ||
<input name="america" id="america" type="text" /> | ||
<input type="hidden" name="pregunta" value="1" /> | ||
|
||
<input type="submit" value="Enviar Respuesta" /> | ||
</form> | ||
|
||
<br/> | ||
|
||
<form method="post" action="respuesta" id="enviar2"> | ||
<label for="portugal"> | ||
¿Cuál es la cápital de Portugal? | ||
</label> | ||
<input name="portugal" id="portugal" type="text" /> | ||
<input type="hidden" name="pregunta" value="2" /> | ||
|
||
<input type="submit" value="Enviar Respuesta" /> | ||
</form> | ||
</div> | ||
|
||
<footer> | ||
<div class="content"> | ||
Curso Node.js | ||
</div> | ||
</footer> | ||
<script> | ||
var enviar1 = document.getElementById("enviar1"); | ||
enviar1.addEventListener("submit", function (e) { | ||
if (document.getElementById("america").value.trim() == "" || | ||
document.getElementById("america").value.trim() == undefined) { | ||
alert("valores vacios"); | ||
e.preventDefault(); | ||
} | ||
}); | ||
var enviar2 = document.getElementById("enviar2"); | ||
enviar2.addEventListener("submit", function (e) { | ||
if (document.getElementById("portugal").value.trim() == "" || | ||
document.getElementById("portugal").value.trim() == undefined) { | ||
alert("valores vacios"); | ||
e.preventDefault(); | ||
} | ||
}); | ||
</script> | ||
</body> | ||
|
||
</html> |