Class: RailsAngularSeo::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_angular_seo/middleware.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



16
17
18
# File 'lib/rails_angular_seo/middleware.rb', line 16

def initialize(app)
  @app = app
end

Class Attribute Details

.base_pathObject

Returns the value of attribute base_path.



10
11
12
# File 'lib/rails_angular_seo/middleware.rb', line 10

def base_path
  @base_path
end

.phantomjs_pathObject

Returns the value of attribute phantomjs_path.



13
14
15
# File 'lib/rails_angular_seo/middleware.rb', line 13

def phantomjs_path
  @phantomjs_path
end

.seo_idObject

Returns the value of attribute seo_id.



11
12
13
# File 'lib/rails_angular_seo/middleware.rb', line 11

def seo_id
  @seo_id
end

.server_nameObject

Returns the value of attribute server_name.



12
13
14
# File 'lib/rails_angular_seo/middleware.rb', line 12

def server_name
  @server_name
end

Instance Method Details

#call(env) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rails_angular_seo/middleware.rb', line 20

def call(env)
  if will_render?(env)
    self.class.server_name ||= env["HTTP_HOST"]
    self.class.phantomjs_path ||= 'phantomjs'
    path = URI("#{env["rack.url_scheme"]}://#{self.class.server_name}#{env["REQUEST_URI"]}")
    path_without_port = "#{env["rack.url_scheme"]}://#{path.host}#{env["REQUEST_URI"]}"
    RailsAngularSeo::Renderer.render(self.class.phantomjs_path, self.class.seo_id, path_without_port)
  else
    @app.call(env)
  end
end