medusa icon indicating copy to clipboard operation
medusa copied to clipboard

feat(medusa): Allow regexp in CORS configuration

Open adrien2p opened this issue 2 years ago • 1 comments

What In some cases, a users that works with a bunch of subdomain would like to be able to configure the cors using a regexp to allow all or a sub set of his sub domains https://discord.com/channels/876835651130097704/877195433649258536/1002330864216195112

Info Cors middleware impl authorised it: https://github.com/expressjs/cors/blob/f038e7722838fd83935674aa8c5bf452766741fb/lib/index.js#L19

adrien2p avatar Jul 28 '22 22:07 adrien2p

🦋 Changeset detected

Latest commit: 535705e5920495a2158e11fa0f2a6763550f7b94

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@medusajs/medusa Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Jul 28 '22 22:07 changeset-bot[bot]

@olivermrbl do you think that pr could be merge at some point?

adrien2p avatar Nov 07 '22 19:11 adrien2p

@adrien2p Yes, I will give this a review tomorrow :)

olivermrbl avatar Nov 07 '22 20:11 olivermrbl

I am attempting to configure ADMIN_CORS with a regex, but I can't seem to make it work. Am I doing something wrong here?

const ADMIN_CORS = `/http\:\/\/localhost\:700\d`

This should allow requests from origins http://localhost:7000, http://localhost:7001, etc.

olivermrbl avatar Nov 15 '22 08:11 olivermrbl

@olivermrbl I ve open a pr in the CORS repo as I can't seam to be able to find the culprit https://github.com/expressjs/cors/issues/292

It is also possible that the changeset need to be updated

adrien2p avatar Nov 15 '22 10:11 adrien2p

It is now working properly, just need to double the \ to avoid them to be escaped /http:\\/\\/localhost:700\\d+$/

adrien2p avatar Nov 16 '22 21:11 adrien2p

That's a great functionality.

Question: I believe we will increase quite a lot the size of the plugins if they now depend on medusa core. Should we think about separating the "utils" to a new package? ps: considering that some people are not using package managers that reuse installed node_modules

carlos-r-l-rodrigues avatar Nov 18 '22 11:11 carlos-r-l-rodrigues

That's a great functionality.

Question: I believe we will increase quite a lot the size of the plugins if they now depend on medusa core. Should we think about separating the "utils" to a new package? ps: considering that some people are not using package managers that reuse installed node_modules

I see what you mean, but plugins already depends on the core as they can extend strategies, interfaces, services, and also are already using some utilities. In that case I am afraid it would mean to separate all of those in different packages. Generally speaking, since the plugins have no dependency to the core, but only as a peer dependency, I don't think it is a problem since the core will then not be installed by the plugin. they are normally used in the server and the server install medusa core already wdyt? let me know if I have miss understood something

adrien2p avatar Nov 18 '22 11:11 adrien2p

Sorry, disregard my comment. I see it's listed as a peerDependencies. Even npm will reuse medusa-code if that's is installed.

carlos-r-l-rodrigues avatar Nov 18 '22 11:11 carlos-r-l-rodrigues

@olivermrbl finally all green

adrien2p avatar Nov 25 '22 10:11 adrien2p

Think we should add a guide for this in our documentation. Wdyt? @adrien2p

cc. @shahednasser

olivermrbl avatar Nov 28 '22 10:11 olivermrbl

Yes I agree, we can take the examples we've put in comments of that pr? And we should mention the usage of the utilities in custom routes

adrien2p avatar Nov 28 '22 10:11 adrien2p

I'll add an issue for it in Linear 👍🏻

shahednasser avatar Nov 28 '22 10:11 shahednasser

@olivermrbl, @adrien2p - can we merge this?

srindom avatar Dec 12 '22 10:12 srindom

Yes, we were just awaiting a green pipeline. After resolving the conflict, we should be good 💪

olivermrbl avatar Dec 12 '22 10:12 olivermrbl

@srindom yes sure, i ve tested it and was waiting for someone else to test as well

adrien2p avatar Dec 12 '22 10:12 adrien2p