I'm using msw on a nuxt application (SSR), I have the mocking setup and working perfectly on the node server and in the browser. This is great when I'm going directly to the API https://api.blah.com.
However, I'm also trying to implement a proxy via my node server instead of going directly to the API.
So the browser request turns from https://api.blah.com to http://localhost:3000/api which then runs through the node server and (using axios) proxy to the API.
It's on that layer i'm looking to utilise the msw + node-request-interceptor and receiving the error.
Here are some extracts from running in DEBUG=*.
Just to note that i'm not trying to mock this endpoint yet.
http POST http://api.blah.com:443/path using [Function: bound proxiedOriginalRequest] +0ms
http override https.request original call +3ms
ERROR Protocol "http:" not supported. Expected "https:"
The request is coming in on (http) http://localhost:3000/api/ but wants to leave on (https) https://api.blah.com this happens with @nuxtjs/axios & @nuxtjs/proxy (uses http-proxy-middleware underneath) modules.
I've seen the quite recent changes to "detect the protocol from agent" and wondering if there is a way to set that protocol rather than infer it from the request.
msw: 0.24.0nodejs: 14.14.0npm: 6.14.8Please also provide your browser version.
Steps to reproduce the behavior:
Protocol "http:" not supported. Expected "https:"Edit
Here is the reproduced issue;
https://github.com/hamishhossack/msw-proxy-bug
Steps to reproduce
yarn dev build the apphttp://localhost:3000Key points
node-request-interceptor to not touch the protocol in node and allow it to pass via the proxied https module.
here is the working request url being mocked;
http://localhost:3000/api/guests/invites/2k3j4h234
PS. Happy to get involved with any changes required, if you can make sense of this. I'll try and make a reproducible repo in the meantime.
Hi @hamishhossack, thanks for reaching us :). I'm going to take a look at your example
I have looked at the code and I think that the issue is here https://github.com/mswjs/node-request-interceptor/blob/50e5aa72ee102a8bec8e2f38e3efc9efa26d5e74/src/utils/getUrlByRequestOptions.ts#L34.
If the options.uri is not defined I think that we should also check the port. If the port is 443 we should use https otherwise we will use the default protocol
Yes certainly looks like it would resolve this use case, I will PR it on node-request-interceptor 馃憤馃徎 Thanks :)
The fix has been published under [email protected]. Please re-install the dependencies to get it in your project.
Thank you for the awesome contribution, @hamishhossack!
Most helpful comment
I have looked at the code and I think that the issue is here https://github.com/mswjs/node-request-interceptor/blob/50e5aa72ee102a8bec8e2f38e3efc9efa26d5e74/src/utils/getUrlByRequestOptions.ts#L34.
If the
options.uriis not defined I think that we should also check the port. If the port is 443 we should use https otherwise we will use the default protocol