question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cors origin RegExp issues

See original GitHub issue

Hey there, first of all thank you for this middleware.

I am having some issues using the regexp with the origin using the cors middleware. When I set the value to be /http:\\/\\/localhost:[0-9]+$/ the regexp is properly constructed. Putting some breakpoints in the lib I can see that the origin is allowed using the regexp

Screenshot 2022-11-15 at 11 26 40

But for un unknown reason after the header are set properly, I still get a cors issue

Screenshot 2022-11-15 at 11 27 01

Funny enough, the cors error happen only on the auth route as you can see here

Screenshot 2022-11-15 at 11 31 07

The cors are setup on app using app.use and then later on the auth routes are added to a Router() and the router is consumed by app.use

Would you have any idea what is happening?

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dougwilsoncommented, Nov 16, 2022

test to use a regexp such as /http://localhost:700\d/ or similar and pass it to to the origin option and see if you obtain the same result as me ☺️ wdyt?

Yea, I tested the regexp locally and there are tests in our test suite as well that are working fine. So something different between the environments and code or something and not sure how to determine that since what i tried before responding works and the test suite verifies thay regexp matching works. I believe absolutely you are having an issue, but just don’t know the cause and how to reproduce it to debug, which is why i asked for one if you’re interested in having me debug 😃

0reactions
adrien2pcommented, Nov 16, 2022

Sorry missed it but I was using /g flag among other tests and it was certainly the culprit.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using a regular expression with CORS - regex - Stack Overflow
One way to do this is to first get the value of the Origin header from the request (this varies from server to...
Read more >
Support regular expressions in CORS origins configuration
Providing regex support when specifying the allowed origins in CORS configuration would be extremely helpful. Currently, there is no documented ...
Read more >
Match CORS 'allowedOrigins' with regular expression in ...
A regular expression value must match the entire value of the Origin header in the HTTP request for it to be considered a...
Read more >
Rack CORS origins via ENV var and Regex
CORS errors are common issues when you have an API-only Rails Application with a separate front end. The basic configuration looks like: Rails....
Read more >
Regular Expression for CORS configuration - Mattermost Forum
Hello! Does anyone knows, can I set regular expression for CORS config, something like (https?:\/\/localhost:[0-9]{1,5})|(https?:\/\/([^\.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found