Is it possible to set baseURL? #1696
Answered
by
kettanaito
Kazuhiro-Mimaki
asked this question in
Q&A
-
Is it possible to set baseURL? For example, const handlers = [
rest.get('http://example.com/xxx', () => {}),
rest.get('http://example.com/yyy', () => {}),
rest.get('http://example.com/zzz', () => {}),
] It is good idea to define module "baseURL". const baseURL = (path: `/${string}`) => `http://example.com${path}`
const handlers = [
rest.get(baseURL('/xxx'), () => {}),
rest.get(baseURL('/yyy'), () => {}),
rest.get(baseURL('/zzz'), () => {}),
] However, I think it is simpler to write the interface like following. rest.baseURL = 'http://example.com'
const handlers = [
rest.get('/xxx', () => {}),
rest.get('/yyy', () => {}),
rest.get('/zzz', () => {}),
] Is it possible? |
Beta Was this translation helpful? Give feedback.
Answered by
kettanaito
Aug 14, 2023
Replies: 1 comment
-
Hi, @Kazuhiro-Mimaki. Please take a look at the existing discussions around this: TL;DR No, MSW provides no means to set a base URL using its API. You should set the base URL by yourself, and the issues I linked above illustrate a few ways how to do that. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
kettanaito
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, @Kazuhiro-Mimaki. Please take a look at the existing discussions around this:
TL;DR No, MSW provides no means to set a base URL using its API. You should set the base URL by yourself, and the issues I linked above illustrate a few ways how to do that.