20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/isomorfeus/asset_manager/rack_middleware.rb', line 20
def call(env)
path_info = env['PATH_INFO']
if path_info.start_with?(@assets_path)
if !Isomorfeus.production?
if path_info.end_with?('.rb.js')
asset_key_module_name = path_info[@assets_path_size..-7]
asset_key, module_name = asset_key_module_name.split('/')
asset_key += '.js'
if Isomorfeus.assets.key?(asset_key)
asset = Isomorfeus.assets[asset_key]
if asset && asset.browser?
if asset.bundle_ruby_modules.key?(module_name)
= { Rack::CONTENT_TYPE => 'application/javascript' }
asset_manager.transition(asset_key, asset)
return [200, , get_content(env, , asset, asset_key, asset.bundle_ruby_modules[module_name][:js])]
end
end
end
elsif path_info.end_with?('.rb.js.map')
asset_key_module_name = path_info[@assets_path_size..-11]
asset_key, module_name = asset_key_module_name.split('/')
asset_key += '.js'
asset = Isomorfeus.assets[asset_key]
if asset && asset.browser?
if asset.bundle_ruby_modules.key?(module_name)
= { Rack::CONTENT_TYPE => 'application/json' }
asset_manager.transition(asset_key, asset)
return [200, , get_content(env, , asset, asset_key, asset.bundle_ruby_modules[module_name][:map])]
end
end
elsif path_info.end_with?('.js.map')
asset_key = path_info[@assets_path_size..-5]
asset = Isomorfeus.assets[asset_key]
if asset && asset.browser?
= { Rack::CONTENT_TYPE => 'application/json' }
asset_manager.transition(asset_key, asset)
return [200, , get_content(env, , asset, asset_key, asset.hash[:js][:map])]
end
elsif path_info.end_with?('.css.map')
asset_key = path_info[@assets_path_size..-9] + '.js'
asset = Isomorfeus.assets[asset_key]
if asset && asset.browser?
= { Rack::CONTENT_TYPE => 'application/json' }
asset_manager.transition(asset_key, asset)
return [200, , get_content(env, , asset, asset_key, asset.hash[:css][:map])]
end
end
end
if path_info.end_with?('.js')
asset_key = path_info[@assets_path_size..-1]
if Isomorfeus.assets.key?(asset_key)
asset = Isomorfeus.assets[asset_key]
if asset && asset.browser?
= { Rack::CONTENT_TYPE => 'application/javascript' }
asset_manager.transition(asset_key, asset)
return [200, , get_content(env, , asset, asset_key, asset.hash[:js][:js])]
end
end
elsif path_info.end_with?('.css')
asset_key = path_info[@assets_path_size..-5] + '.js'
asset = Isomorfeus.assets[asset_key]
if asset && asset.browser?
= { Rack::CONTENT_TYPE => 'text/css' }
asset_manager.transition(asset_key, asset)
return [200, , get_content(env, , asset, asset_key, asset.hash[:css][:css])]
end
end
return [404, {}, 'not found']
elsif Isomorfeus.development? && path_info == Isomorfeus.hmr_websocket_path
if env['rack.upgrade?'] == :websocket
env['rack.upgrade'] = Isomorfeus::AssetManager::ServerSocketProcessor.new
end
WS_RESPONSE
else
@app.call(env)
end
rescue Exception => e
STDERR.puts "#{e.message}\n#{e.backtrace&.join("\n")}\n"
@app.call(env)
end
|