# Api calls getting redirected (Moved Temporarily) using Ember-cli, ember test --server, and http-mock

**URL:** <https://discuss.emberjs.com/t/api-calls-getting-redirected-moved-temporarily-using-ember-cli-ember-test-server-and-http-mock/6715>\
**Category:** Testing\
**Created:** [November 15, 2014, 5:15pm UTC](https://discuss.emberjs.com/t/api-calls-getting-redirected-moved-temporarily-using-ember-cli-ember-test-server-and-http-mock/6715 "2014-11-15T17:15:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bennysghost](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/bennysghost/32/9966_2.png) [@bennysghost](https://discuss.emberjs.com/u/bennysghost)\
**Post date:** [November 15, 2014, 5:15pm UTC](https://discuss.emberjs.com/t/api-calls-getting-redirected-moved-temporarily-using-ember-cli-ember-test-server-and-http-mock/6715/1 "2014-11-15T17:15:20Z")

</div>

I have some http-mock request/responses I’d like to use only in a testing environment. Our API is completely built out, so I’d only like to use the mocks when running ‘ember test --server’ or ‘ember test’ (CI mode). I’m running into a few issues setting this up and was hoping someone had a solution.

When I run 'ember test --server ', tests run at an url that’s like [http://localhost:7357/7150/tests/index.html](http://localhost:7357/7150/tests/index.html)

However, any time a request to the backend is made I get a 302 Moved Temporarily response. For example, when the client does a GET to what I would expect would be my data endpoint url in this testing mode: [http://localhost:7357/brands/1](http://localhost:7357/brands/1), I get the 302 response and the url is redirected to [http://localhost:7357/brands/1/test/index.html](http://localhost:7357/brands/1/test/index.html) (which does not exists)

the mock works fine when I run tests in a browser using port 4200, ie [http://0.0.0.0:4200/tests](http://0.0.0.0:4200/tests)

I think I’m missing some magic configuration somewhere. Anyone know how I can get my ‘ember test --server’ to utilize my mocked out backend using ember-cli’s http-mocks?

---

<div class="post-metadata">

**Author:** ![tspacek](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/tspacek/32/9867_2.png) [@tspacek](https://discuss.emberjs.com/u/tspacek)\
**Post date:** [November 21, 2014, 10:53pm UTC](https://discuss.emberjs.com/t/api-calls-getting-redirected-moved-temporarily-using-ember-cli-ember-test-server-and-http-mock/6715/2 "2014-11-21T22:53:13Z")

</div>

I’m getting the same, did you have any luck working this out?

---

<div class="post-metadata">

**Author:** ![tspacek](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/tspacek/32/9867_2.png) [@tspacek](https://discuss.emberjs.com/u/tspacek)\
**Post date:** [November 23, 2014, 10:02am UTC](https://discuss.emberjs.com/t/api-calls-getting-redirected-moved-temporarily-using-ember-cli-ember-test-server-and-http-mock/6715/3 "2014-11-23T10:02:51Z")

</div>

This SO post had the answer: [javascript - How to get test to access ember-cli server when run in CI mode? - Stack Overflow](http://stackoverflow.com/questions/24053248/how-to-get-test-to-access-ember-cli-server-when-run-in-ci-mode)

And this commit demonstrates it: [enabling CORS in the test server to allow the CI tests to hit it · voluspa/vilive@948962e · GitHub](https://github.com/voluspa/vilive/commit/948962e2e0cfd1a11c4f47bd9438007d505c8d77)

You need to tell `ember test` to hit a running Ember server (which you have made accept CORS), which proxies the request to your test server (e.g. Rails).

Or you could get your test server to accept CORS directly instead.

---

<div class="post-metadata">

**Author:** ![bennysghost](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/bennysghost/32/9966_2.png) [@bennysghost](https://discuss.emberjs.com/u/bennysghost)\
**Post date:** [December 4, 2014, 12:49am UTC](https://discuss.emberjs.com/t/api-calls-getting-redirected-moved-temporarily-using-ember-cli-ember-test-server-and-http-mock/6715/4 "2014-12-04T00:49:33Z")

</div>

thanks. we ended up using Pretender to always stub out api calls in our tests instead

---

<div class="post-metadata">

**Author:** ![kushdilip](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/kushdilip/32/10266_2.png) [@kushdilip](https://discuss.emberjs.com/u/kushdilip)\
**Post date:** [April 21, 2015, 7:02am UTC](https://discuss.emberjs.com/t/api-calls-getting-redirected-moved-temporarily-using-ember-cli-ember-test-server-and-http-mock/6715/5 "2015-04-21T07:02:45Z")

</div>

Have a look at [https://github.com/samselikoff/ember-cli-mirage/](https://github.com/samselikoff/ember-cli-mirage/).

We were also using `http-mock + Pretender` combo earlier. Recently moved to `ember-cli-mirage`, which works flawlessly and gives you best of both.
