I am using Sinatra routes and I would like to interpret, if possible, a normal HTTP address as parameter in a route:
url http://somesite/blog/archives
where the route is:
/http://somesite/blog/archives
The code is:
get '/:url' do |u|
(some code dealing with url)
The various '/' in the HTTP URL are creating problems.
The workaround I found is passing only the URL part represented by 'somesite' in the example above, and then using:
get '/:url' do |u|
buildUrl = "http://#{u}/blog/archives"
(some code dealing with url)
Is there a way to deal directly with the full URL?
This will not work as you specified. As you noticed, the slashes cause trouble. What you can do instead is pass the URL as a querystring param instead of part of the URL.
get '/example' do
url = params[:url]
# do code with url
end
Then you can crawl whatever you want by sending your data to http://yoursite.com/example?url=http://example.com/blog/archives
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With