Sha256: 2aa2b014094e0f8ab89fcbc0f6a1a6ea5407f8a3af2afdf26f7b39a6abb040a2
Contents?: true
Size: 871 Bytes
Versions: 3
Compression:
Stored size: 871 Bytes
Contents
require 'json' require 'sinatra/base' require 'sinatra/support' require 'sinatra/json' require 'redis' require 'sinatra/cross_origin' Encoding.default_external = 'utf-8' if defined?(::Encoding) module BenevolentGaze class BGApp < Sinatra::Base set server: 'thin', connections: [] register Sinatra::CrossOrigin configure do if ENV["REDISTOGO_URL"] uri = URI.parse(ENV["REDISTOGO_URL"]) REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password) else REDIS = Redis.new end end get "/" do r = REDIS if r.get("bg:host:#{request.ip}") redirect to(("http://#{r.get("bg:host:#{request.ip}").strip}")) else redirect to("/") end end post "/" do r = REDIS r.set("bg:host:#{request.ip}", params[:ip]) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
benevolent_gaze-1.0.2 | lib/benevolent_gaze/bgapp.rb |
benevolent_gaze-1.0.1 | lib/benevolent_gaze/bgapp.rb |
benevolent_gaze-1.0.0 | lib/benevolent_gaze/bgapp.rb |