Giter Site home page Giter Site logo

Specify entire subdomain about rack-cors HOT 9 CLOSED

cyu avatar cyu commented on July 23, 2024
Specify entire subdomain

from rack-cors.

Comments (9)

cyu avatar cyu commented on July 23, 2024 28

Sorry - I don't know why I ever said you can do that. Wildcard doesn't work, use a regular expression instead:

config.middleware.use Rack::Cors do
  allow do
    origins /http:\/\/(.*?)\.example\.com/
    resource '*', :headers => :any, :methods => [:get, :post, :options]
  end
end

from rack-cors.

imgarylai avatar imgarylai commented on July 23, 2024 17

This is my regex example:

/\Ahttps?:\/\/([a-zA-Z\d-]+\.){0,}example\.com\/?\z/

My example can match https and end up with top level domain. For example https://example.com.hello.world is not a valid domain.

from rack-cors.

raywu avatar raywu commented on July 23, 2024 11

Does origing have to match http:// or https://? Matching subdomain.example.com has worked for me, but the doc is unclear.

/^(.*\.|)example\.com$/ might work (regexr)

from rack-cors.

cyu avatar cyu commented on July 23, 2024 7

Try this:

config.middleware.use Rack::Cors do
  allow do
    origins '*.example.com'
    resource '*', :headers => :any, :methods => [:get, :post, :options]
  end
end

UPDATE: This example doesn't work. Instead use the regular expression example below.

from rack-cors.

sakirtemel avatar sakirtemel commented on July 23, 2024 2

I've created a wiki for that as it might be useful for the others, later maybe it can be moved to README. Thanks @raywu for the regex and the link it was useful, I copied actually that one to the wiki

from rack-cors.

imi56 avatar imi56 commented on July 23, 2024 1

Sorry - I don't know why I ever said you can do that. Wildcard doesn't work, use a regular expression instead:

config.middleware.use Rack::Cors do
  allow do
    origins /http:\/\/(.*?)\.example\.com/
    resource '*', :headers => :any, :methods => [:get, :post, :options]
  end
end

This will match anything.example.com.co.in as well which might not be desired expectation.

from rack-cors.

ramanbuttar avatar ramanbuttar commented on July 23, 2024

origins '*.example.com' doesn't work. Wildcard is not being read as intended.

from rack-cors.

buren avatar buren commented on July 23, 2024

@ramanbuttar is absolutely right. origins '*.example.com' will not allow test.example.com

from rack-cors.

ryanwjackson avatar ryanwjackson commented on July 23, 2024

did this ever get resolved? Is there a way around it?

from rack-cors.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.