I have a component in my Ember app which returns data from a static markdown file.
didInsertElement() {
fetch('markdown/faqs-content.md').then(response => {
response.text().then(result => {
this.set('markdown', result);
});
});
}
When the app runs, the request goes to http://localhost:4200/markdown/faqs-content.md
and everything works fine.
However, in mirage, I get this error:
Mirage: Your app tried to GET '/markdown/faqs-content.md', but there was no route defined to handle this request. Define a route for this endpoint in your routes() config. Did you forget to define a namespace?
The above happens, even though the following is included in mirage/config.js
:
this.passthrough();
Presumably, this is because the API namespace is not included in the request URL.
The problem can be solved by adding the full URL to passthrough:
this.passthrough('https://localhost:4201/markdown/faqs-content.md');
Doing this has two issues:
- I don't always know the port that the app is served on, and
- I don't want to lose the functionality of using
this.passThrough()
, which automatically invokes pass through for any API requests where there is no corresponding route inmirage/config.js
.
I thus have 2 questions.
-
In
config.js
, is there any way of getting port that Ember server is running on, to allow something likehttps://localhost:${port}/markdown/faqs-content.md
? -
Is there a way that I can configure Mirage to pass through for the request to
https://localhost:4201/markdown/faqs-content.md
, and still allow it to pass through for any other requests that don't have a corresponding route defined?
Aucun commentaire:
Enregistrer un commentaire