class WAB::Impl::Agoo::ExportProxy

A handler that provides missing files in an assets directory where the files are the wab and wab UI files.

Public Class Methods

new(shell) click to toggle source
# File lib/wab/impl/agoo/export_proxy.rb, line 11
def initialize(shell)
  @shell = shell
end

Public Instance Methods

on_request(req, res) click to toggle source
# File lib/wab/impl/agoo/export_proxy.rb, line 15
def on_request(req, res)
  path = (req.script_name + req.path_info)
  query = parse_query(req.query_string)
  path = '/index.html' if '/' == path
  mime = nil
  index = path.rindex('.')
  unless index.nil?
    mime = {
      'css' => 'text/css',
      'eot' => 'application/vnd.ms-fontobject',
      'es5' => 'application/javascript',
      'es6' => 'application/javascript',
      'gif' => 'image/gif',
      'html' => 'text/html',
      'ico' => 'image/x-icon',
      'jpeg' => 'image/jpeg',
      'jpg' => 'image/jpeg',
      'js' => 'application/javascript',
      'json' => 'application/json',
      'png' => 'image/png',
      'sse' => 'text/plain',
      'svg' => 'image/svg+xml',
      'ttf' => 'application/font-sfnt',
      'txt' => 'text/plain',
      'woff' => 'application/font-woff',
      'woff2' => 'font/woff2',
    }[path[index + 1..-1].downcase]
  end
  mime = 'text/plain' if mime.nil?
  content = WAB.get_export(path)
  res.code = 200
  res['Content-Type'] = mime
  res.body = content
rescue Exception => e
  send_error(e, res)
end