Reputation: 291
I am creating a very simple website with a form in it. I have a problem to redirect to a page after doing the post request.
I have tried many things I found on Stackoverflaw but I can't manage to make it work. This is the error I get :
Error: Cannot find module 'html'
HTML :
<form action="/LUNProvisionning" method="post">
<fieldset>
<legend>LUN Provisionning</legend>
<br />
<label>Choix du serveur : </label>
<select id="serveur" name="serveur">
<option value="1">Pas de detection de serveur :'(</option>
</select>
<br />
<label>Volumétrie en Go 5 - 1000 : </label>
<input type="number" min="5" max="1000" value="500" name="volumetrie">
<br />
<label>Type de provisionning : </label>
<select id="provisionning" name="type">
<option value="1">Thin</option>
<option value="2">Deco</option>
</select>
<br/>
<input type="submit" value="Submit">
</fieldset>
</form>
Nodejs:
const express = require('express');
const bodyparser = require('body-parser');
const app = express();
const path = require('path');
const router = express.Router();
app.set('view engine', 'html');
app.use(bodyparser.urlencoded({ extended: false }));
app.use(express.static(__dirname + '/public'));
app.set('views', __dirname + '/public/views');
app.use('/', router);
router.get('/', function (req, res) {
res.sendFile(path.join(__dirname + '/public/views/index.html'));
});
router.get('/VMProvisionning', function (req, res) {
res.sendFile(path.join(__dirname + '\/public/views/VMProvisionning.html'));
});
router.get('/LUNProvisionning', function (req, res) {
res.sendFile(path.join(__dirname + '/public/views/LUNProvisionning.html'));
});
app.post("/VMProvisionning", function (request, response) {
console.log(request.body.environnement);
console.log(request.body.vCPU);
console.log(request.body.RAM);
console.log(request.body.tailledisque);
response.render("\VMProvisionning.html");
});
app.post("/LUNProvisionning", function (request, response) {
console.log(request.body.serveur);
console.log(request.body.volumetrie);
console.log(request.body.type);
response.render("\LUNProvisionning.html");
});
app.listen(8080, function () {
console.log('Running on Port 8080');
});
It should simply redirect to my other page but it doesn't work.
when i go on this website : http://localhost:8080/LUNProvisionning my page is correctly shown.
thank you!
Upvotes: 1
Views: 98
Reputation: 4678
If you don't want to use a templating engine just remove those line and use sendFile (if you don't have a templating engine, you can't use response.render) :
app.set('view engine', 'html');
app.set('views', __dirname + '/public/views');
Upvotes: 1