简体   繁体   English

快速-替代重定向

[英]Express- alternative redirect

So I was wondering if theres a methode in Express to load a specific page for the user without redirecting the user to the html file. 所以我想知道Express中是否有一种方法可以在不将用户重定向到html文件的情况下为用户加载特定页面。

So instead of res.redirect("https://mywebsite.com/subsite"); 因此,而不是res.redirect("https://mywebsite.com/subsite");

maybe theres another method implemented to load the subsite „ subsite.html“ that does not fire the 也许还有另一种方法可以加载子网站“ subsite.html”,但不会触发

app.get(/\/subsite(?:\.html)?$/, function(){});

event. 事件。

So I want to catch all calls to /subsite and /subsite.html check if the browser/client is allowed to enter the site. 因此,我想捕获对/subsite /subsite.html/subsite.html所有调用,以检查是否允许 浏览器/客户端进入该站点。 If all is correct I will let the browser enter the site otherwise I want to implement a redirect. 如果一切正确,我将让浏览器进入站点,否则我想实现重定向。

What I got so far: 我到目前为止所得到的:

app.get(/\/subsite(?:\.html)?$/, function(req, res) {
  let isValid = checkIfUserIsValid() /* my own logic */
  if (isValid) {
   //how to load subsite.html on the client?
  } else res.redirect("https://mywebsite.com/subsite");
});

Note: I need a method cause I'm stuck in a redirection loop. 注意:我需要一种方法,因为我陷入了重定向循环。

app.get(“/xx“, (req, res) => {
    let permissionsOk = // check your user's permissions
    if (permissionsOk) {
        res.send(/* regular page html */);
    } else {
        res.send(/* access denied html */);
    }
});

The idea is that you can have conditional response and serve different html on the same route according to some internal logic 这个想法是您可以有条件地响应,并根据一些内部逻辑在同一路径上提供不同的html

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

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