Class: Embork::Pushstate

Inherits:
Object
  • Object
show all
Defined in:
lib/embork/pushstate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Pushstate

Returns a new instance of Pushstate.



3
4
5
# File 'lib/embork/pushstate.rb', line 3

def initialize(app, options = {})
  @app = app
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



2
3
4
# File 'lib/embork/pushstate.rb', line 2

def app
  @app
end

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/embork/pushstate.rb', line 7

def call(env)
  status, headers, body = @app.call(env)
  if status == 404
    modified_env = env.dup
    modified_env['PATH_INFO'] = '/index.html'
    status, headers, body = @app.call(modified_env)
    headers['Push-State-Redirect'] = 'true'
  end
  [ status, headers, body ]
end