Add support for running CodeOcean under a subpath

* Also refactor (JavaScript) routes
This commit is contained in:
Sebastian Serth
2021-07-06 17:02:12 +02:00
parent 7914608efe
commit 237c225732
14 changed files with 40 additions and 28 deletions

View File

@ -40,7 +40,9 @@ module CodeOcean
config.autoload_paths += extra_paths
config.eager_load_paths += extra_paths
config.action_cable.mount_path = '/cable'
config.relative_url_root = ENV.fetch('RAILS_RELATIVE_URL_ROOT', '/').to_s
config.action_cable.mount_path = "#{ENV.fetch('RAILS_RELATIVE_URL_ROOT', '')}/cable"
config.telegraf.tags = {application: 'codeocean'}

View File

@ -100,7 +100,4 @@ Rails.application.configure do
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
# Run on subfolder in production environment.
# config.relative_url_root = '/co-staging'
end

View File

@ -2,4 +2,7 @@
# Be sure to restart your server when you modify this file.
Rails.application.config.session_store :cookie_store, key: '_code_ocean_session', expire_after: 1.month
Rails.application.config.session_store :cookie_store,
key: '_code_ocean_session',
expire_after: 1.month,
path: Rails.application.config.relative_url_root

View File

@ -4,8 +4,8 @@ Info for this file can be found
github.com/rails/webpacker/blob/master/docs/webpack.md
*/
const { environment } = require('@rails/webpacker')
const { merge } = require('webpack-merge')
const {environment} = require('@rails/webpacker')
const {merge} = require('webpack-merge')
const webpack = require('webpack')
const erb = require('./loaders/erb')
@ -25,6 +25,14 @@ environment.plugins.prepend('Provide', new webpack.ProvidePlugin({
})
)
// This setting will change the absolute path used to refer
// external files (images, fonts, ...) in the generated assets
const relative_url_root = process.env.RAILS_RELATIVE_URL_ROOT || '';
const public_output_path = environment.config.output.publicPath;
environment.loaders.get('file')
.use.find(item => item.loader === 'file-loader')
.options.publicPath = relative_url_root + public_output_path;
environment.loaders.append('erb', erb)
const envConfig = module.exports = environment