简体   繁体   English

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

[英]Node js express res.redirect not working

I have following code and it's failing to redirect to a html page. 我有以下代码,但无法重定向到html页面。 Intention is to redirect the request to a login page as soon as GET request is received on '/' 目的是在“ /”上收到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...')
});

We need to add express.static middleware to serve static files. 我们需要添加express.static中间件来提供静态文件。 ServerApp.use(express.static(__dirname)); ServerApp.use(express.static(__ dirname)); does the job. 做这份工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM