Class: Imagery::Server

Inherits:
Object
  • Object
show all
Includes:
SendFile
Defined in:
lib/imagery/server.rb

Constant Summary

NotFound =
[404, {'Content-Type' => 'text/html'}, ['<h1>File not Found</h1>']].freeze

Constants included from SendFile

Imagery::SendFile::ContentTypes, Imagery::SendFile::CopyHeaders

Instance Method Summary collapse

Methods included from SendFile

#send_file

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/imagery/server.rb', line 7

def call(env)
  Logger.current.info 'Attempting to generate missing file...'

  [SvgGenerator, ImageVariantGenerator].each do |generator|
    if image = generator.from_url(env['imagery.origin_host'], env['PATH_INFO'] + (env['QUERY_STRING'].empty? ? '' : "?#{env['QUERY_STRING']}"))

      return send_file(image)
    end
  end

  Logger.current.info 'No generator available'

  NotFound
end