admin管理员组文章数量:1389978
The MSW documentation for request-url says:
// Only "POST /users" requests match this handler
rest.post('/users', responseResolver)
// Given your application runs on "http://localhost:8080",
// this request handler URL gets resolved to "http://localhost:8080/invoices"
rest.get('/invoices', invocesResolver)
Been searching a lot but can't find some docs on how to change the port. So it could be something like http://localhost:3001
The MSW documentation for request-url says:
// Only "POST https://api.backend.dev/users" requests match this handler
rest.post('https://api.backend.dev/users', responseResolver)
// Given your application runs on "http://localhost:8080",
// this request handler URL gets resolved to "http://localhost:8080/invoices"
rest.get('/invoices', invocesResolver)
Been searching a lot but can't find some docs on how to change the port. So it could be something like http://localhost:3001
1 Answer
Reset to default 6The "localhost:8080" is emphasized above because a relative URL against a default localhost
will resolve to localhost:8080/url
. You don't necessarily have to customize that.
Relative URL
Any relative URL will be relative against the current application's location. So if your application is running on http://localhost:3000
and you defined a relative /user
handler, you get http://localhost:3000/user
automatically.
// If my app runs on :3000, the handler above intercepts
// a GET http://localhost:3000/user. I don't have to specify
// hostnames/ports for relative URLs against the application address.
rest.get('/user', resolver)
Absolute URL
If you need (for some reason) to define a handler for an external localhost service, the one that is not your application, you include its absolute URL:
// My app runs on :3000 but I want to intercept and mock a request
// to another app that runs on localhost:3001. Here's how I do it:
rest.get('http://localhost:3001/user', resolver)
本文标签: javascriptMSW (Mock Service Worker) change port from 8080Stack Overflow
版权声明:本文标题:javascript - MSW (Mock Service Worker) change port from 8080 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744710471a2621098.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论