2015-11-25 11:18:44 -05:00
|
|
|
app = Rails.application
|
2015-02-20 06:44:07 -05:00
|
|
|
|
2018-09-07 03:21:30 -04:00
|
|
|
if (Gitlab.rails5? && app.config.public_file_server.enabled) || app.config.serve_static_files
|
2017-08-15 13:44:37 -04:00
|
|
|
# The `ActionDispatch::Static` middleware intercepts requests for static files
|
|
|
|
# by checking if they exist in the `/public` directory.
|
2015-02-20 17:30:06 -05:00
|
|
|
# We're replacing it with our `Gitlab::Middleware::Static` that does the same,
|
|
|
|
# except ignoring `/uploads`, letting those go through to the GitLab Rails app.
|
|
|
|
|
2018-09-07 03:21:30 -04:00
|
|
|
if Gitlab.rails5?
|
|
|
|
app.config.middleware.swap(
|
|
|
|
ActionDispatch::Static,
|
|
|
|
Gitlab::Middleware::Static,
|
|
|
|
app.paths["public"].first,
|
|
|
|
headers: app.config.public_file_server.headers
|
|
|
|
)
|
|
|
|
else
|
|
|
|
app.config.middleware.swap(
|
|
|
|
ActionDispatch::Static,
|
|
|
|
Gitlab::Middleware::Static,
|
|
|
|
app.paths["public"].first,
|
|
|
|
app.config.static_cache_control
|
|
|
|
)
|
|
|
|
end
|
2017-02-01 14:05:33 -05:00
|
|
|
|
|
|
|
# If webpack-dev-server is configured, proxy webpack's public directory
|
|
|
|
# instead of looking for static assets
|
2017-02-02 15:07:33 -05:00
|
|
|
dev_server = Gitlab.config.webpack.dev_server
|
|
|
|
|
|
|
|
if dev_server.enabled
|
|
|
|
settings = {
|
2017-02-01 14:05:33 -05:00
|
|
|
enabled: true,
|
2017-02-02 15:07:33 -05:00
|
|
|
host: dev_server.host,
|
|
|
|
port: dev_server.port,
|
|
|
|
manifest_host: dev_server.host,
|
2017-05-03 07:22:03 -04:00
|
|
|
manifest_port: dev_server.port
|
2017-02-02 11:46:47 -05:00
|
|
|
}
|
2017-02-01 14:05:33 -05:00
|
|
|
|
2017-02-02 11:46:47 -05:00
|
|
|
if Rails.env.development?
|
2017-02-02 15:07:33 -05:00
|
|
|
settings.merge!(
|
2017-02-02 11:46:47 -05:00
|
|
|
host: Gitlab.config.gitlab.host,
|
|
|
|
port: Gitlab.config.gitlab.port,
|
2017-09-15 08:40:50 -04:00
|
|
|
https: false
|
2017-02-02 11:46:47 -05:00
|
|
|
)
|
|
|
|
app.config.middleware.insert_before(
|
|
|
|
Gitlab::Middleware::Static,
|
2018-04-26 14:47:21 -04:00
|
|
|
Gitlab::Webpack::DevServerMiddleware,
|
2017-02-02 11:46:47 -05:00
|
|
|
proxy_path: app.config.webpack.public_path,
|
2017-02-02 15:07:33 -05:00
|
|
|
proxy_host: dev_server.host,
|
2017-05-03 07:27:17 -04:00
|
|
|
proxy_port: dev_server.port
|
2017-02-02 11:46:47 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2017-02-02 15:07:33 -05:00
|
|
|
app.config.webpack.dev_server.merge!(settings)
|
2017-02-01 14:05:33 -05:00
|
|
|
end
|
2015-02-20 08:39:35 -05:00
|
|
|
end
|