Sha256: 3b14f3dd987c815cc1689914f433fd96fc15eb2e0b14a36d85f5bbeae4e8befe
Contents?: true
Size: 1.24 KB
Versions: 2
Compression:
Stored size: 1.24 KB
Contents
module Acme class App def initialize @filenames = ['', '.html', 'index.html', '/index.html'] @rack_static = ::Rack::Static.new( lambda { [404, {}, []] }, root: File.expand_path('../../public', __FILE__), urls: ['/'] ) end def self.instance @instance ||= Rack::Builder.new do use Rack::Cors do allow do origins '*' resource '*', headers: :any, methods: :get end end run Acme::App.new end.to_app end def call(env) # api response = Acme::API.call(env) # Check if the App wants us to pass the response along to others if response[1]['X-Cascade'] == 'pass' # static files request_path = env['PATH_INFO'] @filenames.each do |path| response = @rack_static.call(env.merge('PATH_INFO' => request_path + path)) return response if response[0] != 404 end end # Serve error pages or respond with API response case response[0] when 404, 500 content = @rack_static.call(env.merge('PATH_INFO' => "/errors/#{response[0]}.html")) [response[0], content[1], content[2]] else response end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
vitals-0.4.0 | integration/multiverse/grape-on-rack/app/acme_app.rb |
vitals-0.3.0 | integration/multiverse/grape-on-rack/app/acme_app.rb |