-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
localhost:45456/start CORS error #39
Comments
Hmm, that's very very strange! That's the start request to the standalone server, which just uses the standard Express cors module. It can do funky things if you pass cors options to it, but I can see that you're not doing that. Is this failing consistently on that machine, or was this a once-off? I've tested your demo locally on my machine and it seems to work fine & very reliably. If you can reproduce this, can you sprinkle some logging into Mockttp's Mockttp should set up CORS here ( |
Ah, one way I can think of that you might hit this is if you run your tests with the HTTP Toolkit server running. HTTP Toolkit starts a standalone server, and does configure it with CORS options, as part of blocking other origins from making XSRF requests to reconfigure the application. I've tested and this shouldn't be possible (your example refuses to start if the standalone server can't startup because the 45456 port is already taken). If you somehow managed to get past that though and then run the tests without realizing that you're using the locked-down standalone server then you'd see something like the issue you're describing. |
Woo-hoo, I was able to make it reproducible: just start HTTP toolkit before starting the Cypress test! It works the other way around: start the Cypress test, you can wait until it passes or not - doesn't matter, but don't close the Chrome window started by Cypress, then start HTTP toolkit fails to start. |
Ah great, glad we've pinned that down. Does your test not fail to startup, complaining the port's already in use? In the short term, that's what should happen, really - Mockttp should loudly fail to start the standalone server straight away. I'd like to avoid making the HTTP Toolkit port configurable, since it makes a bunch of stuff more complicated, but the Mockttp port is already configurable so you can use that to fix this:
That should let you avoid any conflicts in future. |
If that would happen, that would make it way more obvious. But I only see the CORS error, as in the screenshot. I will change the Mockttp proxy factory "control port" to something else, but if the HTTP toolkit would also run on a non-default port (not 45456), that would reduce the chance of conflicts for other users. It doesn't have to be configurable in the HTTP toolkit UI, just a hardcoded different port. But... even then, a chance that those "control ports" will collide still exist. Maybe an optional "proxy factory id" can be supplied on instantiation of the proxy factory and of the remote control, then most of Mockttp users will just not set it, but HTTP toolkit will have it set, and when an unexpected "remote control" knocks to the wrong "proxy factory", we would respond with an informative error. |
This is quite surprising. On my machine, this happens:
Running Can you share the console output you're seeing? What version of node are you using as well? That could be relevant. This is where port conflicts should be failing I think - trying to start a standalone server should fail very loudly & clearly at the moment of conflict, just like trying to start a mock server does in the browser code. The error could be improved and explained better here of course, but either way there should already be a big loud error! |
Hi Tim! I've got node v12.13.0. I don't have these errors. We can compare the output of
|
Anyway, I guess using a port other than 45456 for HTTP toolkit (so it will less likely collide with the default Mockttp port) would be good enough. |
Hi Tim! I want to use |
Hi @mvasin! Thanks for chasing this up, good catch. I've now changed the Mockttp default to 45454 which won't conflict with HTTP Toolkit (which uses 45456 & 45457), and I've also added a That's all on master, but not quite released yet, watch this space. Would that work for you? |
Sounds spectacular! :D |
This is now released, as part of Mockttp 1.0.0 🎉 Give it a go, let me know if you have any other trouble at all. |
Thank you, and - congratulations with v.1.0, Tim! |
Recently I created a repo to showcase how Mockttp can be controlled from within Cypress tests: https://github.com/mvasin/cypress-mockttp
The tests pass in GitHub Actions, but locally I bumped into an interesting problem.
The example repo fails with a CORS error, but only on one of my Macs. The other Mac does not have CORS issues. All I do on both Macs is
Here's the screenshot from the first Mac:
And here's the screenshot from the second Mac:
You can see on the screenshots that the
/start
pre-flight request on the first Mac does containaccess-control-allow-origin: *
, while the second doesn't, hence the CORS error on the second screenshot.How can that happen given the same MacOS (10.5.5), same node version (12.13.0), the same Chrome version (83) that comes with the same Cypress version... I'm puzzled.
Given that I can't reproduce the issue myself 😅 (on the second computer) I'm fine with closing it if no one has a hint on what could it be.
The text was updated successfully, but these errors were encountered: