Sha256: b481bb31b86c0c583b3a2c33fac9f7985c749a7ff5a86da07aea88532d306f1f

Contents?: true

Size: 1.1 KB

Versions: 5

Compression:

Stored size: 1.1 KB

Contents

require 'sinatra'
require 'rack/ssl'

module SnowmanIO
  class Web < Sinatra::Base
    set :public_folder, File.dirname(__FILE__) + "/ui"
    set :views, File.dirname(__FILE__) + "/ui"

    use Rack::SSL, exclude: Proc.new { |env|
      ENV['DEV_MODE'].to_i == 1 || !Setting.force_ssl?
    }

    before do
      unless Setting.get(SnowmanIO::BASE_URL_KEY).present?
        Setting.set(SnowmanIO::BASE_URL_KEY, request.base_url)
      end
    end

    get "/ping" do
      "PONG"
    end

    # Ember application
    get '/*' do
      # Dont cache index page
      # http://stackoverflow.com/questions/49547/making-sure-a-web-page-is-not-cached-across-all-browsers
      headers["Cache-Control"] = "no-cache, no-store, must-revalidate" # HTTP 1.1.
      headers["Pragma"] = "no-cache" # HTTP 1.0.
      headers["Expires"] = "0" # Proxies.

      # replace version only on production.
      if ENV["DEV_MODE"].to_i == 1
        File.read(File.expand_path("../ui/index.html", __FILE__))
      else
        File.read(File.expand_path("../ui/index.html", __FILE__)).sub("__VERSION__", SnowmanIO::VERSION)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
snowman-io-0.5.1 lib/snowman-io/web.rb
snowman-io-0.5.0 lib/snowman-io/web.rb
snowman-io-0.4.0 lib/snowman-io/web.rb
snowman-io-0.3.1 lib/snowman-io/web.rb
snowman-io-0.3.0 lib/snowman-io/web.rb