Class: GitAuth::AuthSetupMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/gitauth/auth_setup_middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ AuthSetupMiddleware

Returns a new instance of AuthSetupMiddleware.



22
23
24
25
# File 'lib/gitauth/auth_setup_middleware.rb', line 22

def initialize(app)
  @app = app
  @files = Rack::File.new(GitAuth::BASE_DIR.join("public").to_s)
end

Instance Method Details

#_call(env) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/gitauth/auth_setup_middleware.rb', line 31

def _call(env)
  if GitAuth::WebApp.has_auth?
    @app.call(env)
  elsif env["PATH_INFO"].include?("/gitauth.css")
    @files.call(env)
  else
    content = ERB.new(File.read(GitAuth::BASE_DIR.join("views", "auth_setup.erb"))).result
    headers = {"Content-Type" => "text/html", "Content-Length" => Rack::Utils.bytesize(content).to_s}
    [403, headers, [content]]
  end
end

#call(env) ⇒ Object



27
28
29
# File 'lib/gitauth/auth_setup_middleware.rb', line 27

def call(env)
  dup._call(env)
end