使用流星路由器重定向到外部 URL [英] Redirect to an external URL using meteor router

查看:54
本文介绍了使用流星路由器重定向到外部 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用流星路由器包.我想从流星应用程序重定向到外部 URL.也就是说,当我将我的应用程序 url 指向 http://localhost:3000/goexternal 时,它应该转到外部站点.

I am using the meteor router package. I want to redirect to an external URL from the meteor app. That is, when I point my app url to http://localhost:3000/goexternal, it should go to an external site.

有什么办法可以用路由器包来做到这一点吗?如果路由器包不支持此要求,我们如何解决?

Is there some way we can do this with the router package? If the router package doesn't support this requirement, how can we do a work around?

推荐答案

最简单的方法是将重定向放在中间件中:

The easiest way to achieve this is to put the redirect in middleware:

WebApp.connectHandlers.stack.splice(0, 0, {
  route: '/goexternal',
  handle: function(req, res, next) {
    res.writeHead(302, {
      'Location': 'http://whatever',
    });
    res.end();
  },
});

这篇关于使用流星路由器重定向到外部 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆