English 中文(简体)
处理快车道的再航道,同时避免改道
原标题:Handling redirection in ExpressJS while avoiding redirect loop

这是我第一次使用“快车”编码。 当用户通过外 oAuth提供商签名时,我仍需要他们在返回现场后提供电子邮件。 I m 基本将其定为数据库中的不活动,并核对req.session.active

我做的是做什么。

app.all( * , function(req, res, next) {
    if(!req.session.active) {
        if(req.path ==  /complete_signup ) {
            next();
        } else {
            return res.redirect( /complete_signup );            
        }
    }
});

但这似乎在发挥作用。 如果用户已经重新定位,我怎么能够仔细检查?

如果你可以建议一种除<代码>pp.all(<>>>/code>以外的方法,那也会奏效。

EDIT:

第二,这项工作正在进行之中,但外部资源(例如表格、javascripts等)似乎都没有装上,因为它们没有打上<条码>req.path<>。

问题回答

您可使用<代码>express-redirect-loop中文本(使用会议,因为吉大港山区移入器头目不可靠)。 这只能满足支持 co鱼储存/仓储(例如浏览器)的要求。

const express = require( express );
const session = require( express-session );
const redirectLoop = require( express-redirect-loop );

const app = express();

app.use(
  session({
    secret:  test ,
    resave: false,
    saveUninitialized: true
  })
);

app.use(redirectLoop());

app.get( / , (req, res) => res.sendStatus(200));
app.get( /bar , (req, res) => res.redirect( /foo ));
app.get( /foo , (req, res) => res.redirect( /foo ));
app.get( /baz , (req, res) => res.redirect( /bar ));

app.listen(3000);




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签