TypeError: Protocol "http:" not supported. Expected "https:"TypeError [ERR_INVALID_PROTOCOL]: Protocol "http:" not supported. Expected "https:"
See original GitHub issueDescribe the bug
A clear and concise description of what the bug is.
Environment
msw: 0.19.5
nodejs: 12.8.2
npm: 6.14.5
Please also provide your browser version.
To Reproduce
Steps to reproduce the behavior:
rest.get('/api/users*', (req, res, ctx) => {
return res(ctx.json(apiresponse))
})
when i write this on our source i get this error always.
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Node js Error: Protocol "https:" not supported. Expected "http:"
I use the http get method for a data set, and I am not sure if it is working properly. When I run...
Read more >Protocol "http:" not supported. Expected "https:"
In my application when I try to login with Auth0, I get the following error and the login fails. Protocol "http:" not supported....
Read more >Making an HTTP Request in Node.js - Mastering JS
You will get a Protocol "https:" not supported. Expected "http:" error if you call http.request() with an HTTPS URL. You need to use...
Read more >Node js Error: Protocol "https:" not supported. Expected "http:"
JavaScript : Node js Error: Protocol " https :" not supported. Expected " http :" [ Gift : Animated Search Engine : https...
Read more >Node Js Error: Protocol "Https:" Not Supported ... - ADocLib
Node Js Error: Protocol "Https:" Not Supported. Expected "Http:". java -jar jenkins-cli.jar -s https://jenkins.example.com help [command] you use the -i ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The issue is that relative URLs do not exist in NodeJS. All requests in NodeJS must have an absolute URL (either explicit or implicit).
When you write
/api/users
in your request handler route, it’s always transformed into an absolute URL. When it’s running in a browser, it’s matched against the currentlocation.origin
. In NodeJS, there is no such concept as “location”. However, certain DOM-like environments (like jsdom) polyfilllocation
and set it to a hard-coded"localhost:XXXX"
string. This is the reason why a relative route may work in both in-browser development and integration tests that run in NodeJS.Solution
You can choose one of the following ways to solve this issue:
This approach is preferable, just make sure you request the same endpoint during development, or in a browser (if applicable). If using the same absolute request URL is constrained (for any reasons), consider having a different request URL depending on the environment. For example:
This is generally not recommended, because this will match all requests that end with
/api/users
. For example, if your app performs ahttps://google.com/api/users
request, that one would get matched as well.I can also suggest to omit the
*
(asterisk) at the end of your route. Request query parameters and hash are stripped off, and never taken into account when matching requests. However, by making a permissive route like/api/users*
you also match against any child route (i.e./api/users/messages/abc-123
).Hi @kettanaito
This is how i call the actual api
I am running mocks on nodejs.
no other setup for “setupServer” just the basic