Skip to content

Commit

Permalink
Adding support for relative URL root path (#5067)
Browse files Browse the repository at this point in the history
* Backend: Added support for relative URL root.

* Frontend: Changed javascript building design.
	+ Added relative URL root path injection to js builds.

* Frontend: Added support for relative URL root.

* Backend: Fixed hardcoded BBB logo pathname.
  • Loading branch information
KH-Amir-TN authored Mar 27, 2023
1 parent 4847f05 commit bd5b311
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Procfile.dev
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
web: bin/rails server -p $PORT
js: yarn build:development --watch
js: yarn build:development
css: yarn build:development:css --watch
2 changes: 1 addition & 1 deletion app/javascript/helpers/Axios.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const axiosInstance = axios.create(
// `baseURL` will be prepended to `url` unless `url` is absolute.
// It can be convenient to set `baseURL` for an instance of axios to pass relative URLs
// to methods of that instance.
baseURL: '/api/v1',
baseURL: `${process.env.RELATIVE_URL_ROOT}/api/v1`,

// `headers` are custom headers to be sent
headers: {
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/i18n.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ i18next
.use(HttpApi)
.init({
backend: {
loadPath: '/api/v1/locales/{{lng}}.json',
loadPath: `${process.env.RELATIVE_URL_ROOT}/api/v1/locales/{{lng}}.json`,
},
load: 'currentOnly',
fallbackLng: (locale) => {
Expand Down
1 change: 1 addition & 0 deletions app/javascript/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const router = createBrowserRouter(
<Route path="/rooms/:friendlyId/join" element={<RoomJoin />} />
</Route>,
),
{ basename: process.env.RELATIVE_URL_ROOT },
);

const rootElement = document.getElementById('root');
Expand Down
8 changes: 6 additions & 2 deletions app/services/setting_getter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ def call
setting: { name: @setting_name }
)

value = if @setting_name == 'BrandingImage' && setting.image.attached?
rails_blob_path setting.image, only_path: true
value = if @setting_name == 'BrandingImage'
if setting.image.attached?
rails_blob_path setting.image, only_path: true
else
ActionController::Base.helpers.image_path('bbb_logo.png')
end
else
setting&.value
end
Expand Down
5 changes: 4 additions & 1 deletion config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@

require_relative 'config/environment'

run Rails.application
map Greenlight::Application.config.relative_url_root do
run Rails.application
end

Rails.application.load_server
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,7 @@ class Application < Rails::Application
config.bigbluebutton_endpoint = File.join(config.bigbluebutton_endpoint, '/api/') unless config.bigbluebutton_endpoint.end_with?('api', 'api/')

config.bigbluebutton_secret = ENV.fetch('BIGBLUEBUTTON_SECRET', '8cd8ef52e8e101574e400365b55e11a6')

config.relative_url_root = ENV.fetch('RELATIVE_URL_ROOT', '/')
end
end
2 changes: 2 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,6 @@

# Annotate rendered view with file names.
# config.action_view.annotate_rendered_view_with_filenames = true

config.relative_url_root = '/'
end
25 changes: 25 additions & 0 deletions esbuild.dev.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as esbuild from 'esbuild';

const relativeUrlRoot = (process.env.RELATIVE_URL_ROOT || '').replace(/\/$/, '');

await esbuild.build({
entryPoints: ['app/javascript/main.jsx'],
bundle: true,
sourcemap: true,
outdir: 'app/assets/builds',
loader: {
'.png': 'dataurl',
'.svg': 'text',
},
watch: {
onRebuild: (error, result) => {
if (error) console.error('watch build failed:', error);
else console.log('watch build succeeded:', result);
},
},
define: {
'process.env.RELATIVE_URL_ROOT': `"${relativeUrlRoot}"`,
},
});

console.log('watch build started');
19 changes: 19 additions & 0 deletions esbuild.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as esbuild from 'esbuild';

const relativeUrlRoot = (process.env.RELATIVE_URL_ROOT || '').replace(/\/$/, '');

await esbuild.build({
entryPoints: ['app/javascript/main.jsx'],
bundle: true,
minify: true,
outdir: 'app/assets/builds',
loader: {
'.png': 'dataurl',
'.svg': 'text',
},
define: {
'process.env.RELATIVE_URL_ROOT': `"${relativeUrlRoot}"`,
},
});

console.log('watch build finished');
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
"yup": "^0.32.11"
},
"scripts": {
"build": "esbuild app/javascript/*.* --bundle --outdir=app/assets/builds --loader:.png=dataurl --minify",
"build": "node esbuild.mjs",
"build:css": "sass ./app/assets/stylesheets/application.bootstrap.scss ./app/assets/builds/application.css --no-source-map --load-path=node_modules --style compressed",
"build:development": "esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds --loader:.png=dataurl",
"build:development": "node esbuild.dev.mjs",
"build:development:css": "sass ./app/assets/stylesheets/application.bootstrap.scss ./app/assets/builds/application.css --no-source-map --load-path=node_modules"
},
"devDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ REDIS_URL=
# [en, ar, fr, es]
#DEFAULT_LOCALE=en

# Set this if you like to deploy Greenlight on a relative root path other than /
#RELATIVE_URL_ROOT=/gl

0 comments on commit bd5b311

Please sign in to comment.