R
R
rutaka nashimo2015-06-16 13:14:56
ruby
rutaka nashimo, 2015-06-16 13:14:56

How to build links in Sinatra considering reverse proxy?

The Sinatra documentation for the url helper says:

To form a URL, you should use the url method, for example in Haml: This method takes into account Rack reverse proxies and routers if they are present.
%a{:href => url('/foo')} foo

I have a Sinatra application deployed that uses a url helper to build links in templates - this application is a gem and it is highly undesirable to change its code.
I had a need to add http-auth to some routes - for this I raised nginx, however, due to the fact that the url helper builds links without taking into account the proxy, the user gets to the pages bypassing the proxy. The question is how to make the url helper build links based on the proxy, or build relative links?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
_
_ _, 2015-06-16
@rutaka_n

The way "on the forehead" is to change the information in env before processing the request.
Something like this. It is possible at the Rack level, it is possible at the application level.

before do
    env['PATH_INFO'].sub!(/^\/blah/, '')
end

From there, Sinatra will use these values ​​for its needs.
Make pp env, see which keys are responsible for what and change.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question