// 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)一直在搜索,但找不到一些关于如何更改端口的文档。所以它可能是类似于http://localhost:3001
发布于 2022-03-22 19:58:40
上面强调了"localhost:8080“,因为默认localhost的相对URL将解析为localhost:8080/url。你不一定要定制它。
相对URL
任何相对URL都将相对于当前应用程序的位置。因此,如果您的应用程序在http://localhost:3000上运行,并且定义了一个相对的/user处理程序,那么您将自动获得http://localhost:3000/user。
// 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)绝对URL
如果您需要(出于某种原因)为外部localhost服务(不是您的应用程序)定义一个处理程序,则需要包含它的绝对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)https://stackoverflow.com/questions/71528041
复制相似问题