ember-cli-mirage尝试对auth0(外部)URL进行存根

时间:2019-05-27 16:47:07

标签: ember.js auth0 ember-simple-auth ember-cli-mirage

我正在开发一个新的Ember.js项目,并使用ember-cli-mirage发出我的请求。该项目将使用ember-simple-auth和Auth0进行用户身份验证。我开始在我的项目中实施它们,但是当我尝试使用Auth0登录模式注册我的Google帐户时,在控制台中出现了一个奇怪的错误:

Your Ember app tried to GET 'https://(my auth0 domain).auth0.com/userinfo',
but there was no route defined to handle this request.
Define a route that matches this path in your
mirage/config.js file. Did you forget to add your namespace?

(我的auth0域在上面已编辑)

我不知道Mirage为什么会尝试将请求存根到外部URL。我正在阅读Mirage文档,并尝试在this.passthrough()文件中使用mirage/config.js,因此Mirage会发出真正的请求,但这似乎没有任何效果(我猜想它仅明确适用于在配置文件中定义的namespace

任何人都可以帮助我了解为什么会发生这种情况以及如何阻止Mirage这样做吗?谢谢!

1 个答案:

答案 0 :(得分:2)

Ember CLI Mirage默认情况下拦截 all ajax(XMLHttpRequest)和fetch请求。您必须使用server.passthrough()方法将应通过的请求列入白名单。 (thisserver中的mirage/config.js实例。)您可以将相对URL和绝对URL与server.passthrough以及所有路由处理程序一起使用。因此server.passthrough('https://(my auth0 domain).auth0.com/userinfo')应该可以解决您的问题。