Sunday, 23 April 2017

Nodejs + Express always returning index.html

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);



via Clomez

No comments:

Post a Comment