So, what is it, im not seeing here?
The problem is that no matter what i put as a file in:
app.get('/', function(req, res){
res.sendfile(__dirname + "/index2");
});
It seem to always return index.html.
As of now it says index2.html which indeed is a legit file
with HTML page but whenever i run this server and go to localhost:8080 it
will still serve the basic index.html not index2.html.
Also changing index.html will bring up the changes so its not cache problem i think.
But then again if you press the submit button, the app.post will work just fine and redirect you to kiitos.html
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser());
app.use(express.static(__dirname + '/'))
app.get('/', function(req, res){
res.sendfile(__dirname + "/index2.html");
});
app.post('/', function(req, res){
var code = req.body.code;
console.log(code);
res.sendFile( __dirname + "/kiitos.html");
});
app.listen(8080);
Your static folder is the one that serves the index.html file because its your root folder.
try creating a public folder for static files (like images, scripts and css files) and move your html files into a views folder and then use:
// save static files like images, scripts and css in `public`...
app.use(express.static(__dirname + '/public'))
app.get('/', function(req, res){
// save html files in the `views` folder...
res.sendfile(__dirname + "/views/index2.html");
});
app.post('/', function(req, res){
var code = req.body.code;
console.log(code);
res.sendFile( __dirname + "/views/kiitos.html");
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With