class Smooth::Middleware
Public Class Methods
new(app, _options = {})
click to toggle source
# File lib/smooth.rb, line 170 def initialize(app, _options = {}) @app = app @dist = Smooth.developer_tools_root.join('dist') @static = Rack::Directory.new(@dist) end
Public Instance Methods
call(env)
click to toggle source
# File lib/smooth.rb, line 176 def call(env) path = env['PATH_INFO'] if path.match(/smooth-developer-tools/) if path == '/smooth-developer-tools' env['PATH_INFO'] = '/index.html' end env['PATH_INFO'].gsub!('/smooth-developer-tools/', '/') path = env['PATH_INFO'] path_exists = @dist.join("#{ path }".gsub(/^\//, '')).exist? if path == '/' path = '/index.html' elsif path.match(/\.\w+/) elsif !path_exists path = '/index.html' end env['PATH_INFO'] = path @static.call(env) else @app.call(env) end end