Class: Smooth::Middleware
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, _options = {}) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, _options = {}) ⇒ Middleware
Returns a new instance of Middleware.
170 171 172 173 174 |
# File 'lib/smooth.rb', line 170 def initialize(app, = {}) @app = app @dist = Smooth.developer_tools_root.join('dist') @static = Rack::Directory.new(@dist) end |
Instance Method Details
#call(env) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# 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 |