节点js表示res.redirect无法正常工作

时间:2017-07-13 09:18:04

标签: node.js express

我有以下代码,但未能重定向到html页面。意图是在' /'

上收到GET请求后立即将请求重定向到登录页面
var express=require('express')
var cookieParser=require('cookie-parser');
var path=require('path');
var bodyParser=require('body-parser');
var ServerApp=express();

ServerApp.get('/',function (req,res){
        res.redirect('./login.html');
        res.end();

});

ServerApp.listen(8080,function(){
                console.log('Server now listening on port 8080...')
});

1 个答案:

答案 0 :(得分:1)

我们需要添加express.static中间件来提供静态文件。 ServerApp.use(express.static(__目录名));做到了。

相关问题