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.



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

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_optionsObject

Returns the value of attribute phantomjs_options.



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

def phantomjs_options
  @phantomjs_options
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



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

def call(env)
  if will_render?(env)
    self.class.server_name ||= env["HTTP_HOST"]
    self.class.phantomjs_path ||= 'phantomjs'
    self.class.phantomjs_options ||= ["--ssl-protocol=any"]
    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, {phantomjs_options: self.class.phantomjs_options})
  else
    @app.call(env)
  end
end