会话令牌过期时如何将用户redirect到login页面?

我有Marionette + Node应用程序。 当令牌过期时,应用程序不作出反应,用户不会redirect到LogIn页面。 我的问题是 – 如何监听节点的会话令牌状态?

先生,祝你好运。 让我简单介绍一下请求处理程序,端点和中间件。

Express.js是非常常见的请求处理程序。 请求处理程序,做他们听起来像他们一样。 他们处理请求; 更具体的http请求。 你可以在网上find很多关于如何用express.js创build基本端点的例子。

现在更重要的是中间件。 至less在中间件中是在到达的请求之间插入的软件,以及要达到的终点。

我将使用Express语法。

假设我有一个端点foo:

Router.get('/foo', function(req, res) {}); 

但是,此端点只能在特定条件下访问。 因此,我在该请求处理程序定义中插入了一个中间件:

  Router.get('/foo', function iAmAMiddleware(req, res, next) { Here you can implement any logic you want. you have access to the request, and the response. Meaning that if something in wrong in the request, then you can return a response from here like res.send(404); BUT if all checks out all you have to do is call next() and the flow will continue into the actual handler function. }, function iAmTheEndpointHandler(req, res) {}) 

中间件的使用是巨大的。 谷歌expression中间件,你会发现很多信息。

祝你好运。