Javascript Nodejs+;Express始终返回index.html

Javascript Nodejs+;Express始终返回index.html,javascript,html,node.js,express,Javascript,Html,Node.js,Express,那么,这是什么,我在这里没有看到 问题是,无论我将什么作为文件放入: app.get('/', function(req, res){ res.sendfile(__dirname + "/index2"); }); 它似乎总是返回index.html。 现在它说的是index2.html,这确实是一个合法的文件 使用HTML页面,但每当我运行此服务器并转到localhost:8080it 仍将提供基本的index.html而不是index2.html 同时更改index.html也会

那么,这是什么,我在这里没有看到

问题是,无论我将什么作为文件放入:

app.get('/', function(req, res){
    res.sendfile(__dirname + "/index2");
});
它似乎总是返回
index.html
。 现在它说的是
index2.html
,这确实是一个合法的文件 使用HTML页面,但每当我运行此服务器并转到
localhost:8080
it 仍将提供基本的
index.html
而不是
index2.html

同时更改
index.html
也会带来更改,因此我认为这不是缓存问题

但是,如果您再次按下提交按钮,app.post将正常工作,并将您重定向到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);

静态文件夹是为
index.html
文件服务的文件夹,因为它是您的根文件夹

尝试为静态文件(如图像、脚本和css文件)创建
public
文件夹,并将
html
文件移动到
views
文件夹中,然后使用:

// 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");
});