Pergunta

I have this simple rack middleware written to rewrite my subdomain :

def call(env)
  request = Rack::Request.new(env)

    if request.host.starts_with?("something-something")
      [301, { "Location" => request.url.gsub('something-something','site-i-want') }, self]
    else
      @app.call(env)
    end

And this works fine on development. But in production I get an error calling .each for TheNameOfMyRackMiddleware

Is there something that looks strangely syntactically incorrect about how I'm writing this?

I want this someting-something.mywebsite.com to go to site-i-want.mywebsite.com

I also tried it directly with my routes with this :

constraints :subdomain => 'something-something' do
  redirect { |p, req| req.url.sub('something-something', 'site-i-want') }
end  

Which works fine on development. But doesn't route before I get my failure saying that the site does not exist.

Entirely open to anyway of getting this accomplished.

Foi útil?

Solução

How about trying this in your routes:

constraints subdomain: 'something-something' do
  get ':any', to: redirect(subdomain: 'site-i-want', path: '/%{any}'), any: /.*/
end

It basically catches any request to the 'something-something' domain, and rewrites it with the existing path, but new subdomain.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top