首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MSW (模拟服务工人)从8080更改端口

MSW (模拟服务工人)从8080更改端口
EN

Stack Overflow用户
提问于 2022-03-18 13:49:53
回答 1查看 1.2K关注 0票数 0

要求的垃圾文件-url说:

代码语言:javascript
复制
// 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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-03-22 19:58:40

上面强调了"localhost:8080“,因为默认localhost的相对URL将解析为localhost:8080/url。你不一定要定制它。

相对URL

任何相对URL都将相对于当前应用程序的位置。因此,如果您的应用程序在http://localhost:3000上运行,并且定义了一个相对的/user处理程序,那么您将自动获得http://localhost:3000/user

代码语言:javascript
复制
// 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:

代码语言:javascript
复制
// 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)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71528041

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档