Sha256: 25035d246bea1682d0400694b138d33d71c0ee10602237be15b94c87b9b34d29

Contents?: true

Size: 719 Bytes

Versions: 2

Compression:

Stored size: 719 Bytes

Contents

require 'sinatra/base'

module Sinatra
  module Presence

    def self.registered(app) 
      app.set :local_authority, 'http://127.0.0.1:9292' # http://en.wikipedia.org/wiki/URI_scheme 

      app.before do
        if(request.cookies["local_url"].nil?)
          new_url = request.url.gsub("#{request.scheme}://#{request.host_with_port}", "#{settings.local_authority}").gsub("/local", "") 
          response.set_cookie(:local_url, value: new_url, expires: Time.now + 600)
        end
      end

      app.get '/local' do
        new_url = request.url.gsub("#{request.scheme}://#{request.host_with_port}", "#{settings.local_authority}").gsub("/local", "") 
        redirect to(new_url)
      end 
    end 

  end 
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sinatra-presence-0.0.4 lib/sinatra/presence.rb
sinatra-presence-0.0.3 lib/sinatra/presence.rb