From ed38ef85850811fdc68d3c9ca87eb25457d9d153 Mon Sep 17 00:00:00 2001 From: Fabian Wilkens Date: Wed, 12 May 2021 19:07:27 +0200 Subject: [PATCH] Activate path url --- conf/env.sample | 3 +++ manifest.json | 9 +++++++++ scripts/change_url | 4 ++-- scripts/install | 12 ++++++++++-- scripts/upgrade | 18 ++++++++++++++++++ sources/patches/app-00-add-path-url.patch | 12 ++++++++++++ 6 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 sources/patches/app-00-add-path-url.patch diff --git a/conf/env.sample b/conf/env.sample index de053c2..120447c 100644 --- a/conf/env.sample +++ b/conf/env.sample @@ -17,3 +17,6 @@ DATADOG_ENABLED=false DEV_DEFAULT_SYNC_SERVER=https://sync.standardnotes.org DEV_EXTENSIONS_MANAGER_LOCATION=public/extensions/extensions-manager/dist/index.html DEV_BATCH_MANAGER_LOCATION=public/extensions/batch-manager/dist/index.min.html + +# Sub-URI +RAILS_RELATIVE_URL_ROOT=/ diff --git a/manifest.json b/manifest.json index d3bac66..e8ecf45 100644 --- a/manifest.json +++ b/manifest.json @@ -34,6 +34,15 @@ "type": "domain", "example": "example.com" }, + { + "name": "path", + "type": "path", + "example": "/notes", + "default": "/", + "help": { + "en": "You can use extensions only without a path url." + } + }, { "name": "is_public", "type": "boolean", diff --git a/scripts/change_url b/scripts/change_url index cb1a90d..386886c 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -17,8 +17,7 @@ old_domain=$YNH_APP_OLD_DOMAIN old_path=$YNH_APP_OLD_PATH new_domain=$YNH_APP_NEW_DOMAIN -#new_path=$YNH_APP_NEW_PATH -new_path="/" +new_path=$YNH_APP_NEW_PATH app=$YNH_APP_INSTANCE_NAME @@ -108,6 +107,7 @@ fi config_file="$final_path/live/.env" ynh_replace_string --match_string="APP_HOST=http://localhost:3001" --replace_string="APP_HOST=https://$new_domain${new_path%/}" --target_file="$config_file" +ynh_replace_string --match_string="RAILS_RELATIVE_URL_ROOT=$old_path" --replace_string="RAILS_RELATIVE_URL_ROOT=$new_path" --target_file="$config_file" #================================================= diff --git a/scripts/install b/scripts/install index b83889c..9f42047 100644 --- a/scripts/install +++ b/scripts/install @@ -25,8 +25,7 @@ ynh_abort_if_errors #================================================= domain=$YNH_APP_ARG_DOMAIN -#path_url=$YNH_APP_ARG_PATH -path_url="/" +path_url=$YNH_APP_ARG_PATH is_public=$YNH_APP_ARG_IS_PUBLIC app=$YNH_APP_INSTANCE_NAME snserver_domain=$YNH_APP_ARG_SNSERVER_DOMAIN @@ -88,6 +87,14 @@ pushd "$final_path/live" git submodule update --init --recursive --quiet popd +# Apply Patch +if [ -f "$YNH_CWD/../sources/patches/app-00-add-path-url.patch" ] +then + pushd "$final_path/live" + patch --strip=1 < "$YNH_CWD/../sources/patches/app-00-add-path-url.patch" + popd +fi + #================================================= # NGINX CONFIGURATION #================================================= @@ -134,6 +141,7 @@ if [ "$snserver_domain" = "" ]; then snserver_domain="sync.standardnotes.org" fi ynh_replace_string --match_string="SF_DEFAULT_SERVER=http://localhost:3000" --replace_string="SF_DEFAULT_SERVER=https://$snserver_domain" --target_file="$config_file" +ynh_replace_string --match_string="RAILS_RELATIVE_URL_ROOT=.*$" --replace_string="RAILS_RELATIVE_URL_ROOT=$path_url" --target_file="$config_file" #================================================= # BUILDING diff --git a/scripts/upgrade b/scripts/upgrade index 3ef94dc..22e2204 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -53,6 +53,24 @@ if [ -z "$final_path" ]; then ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi +if ynh_compare_current_package_version --comparison lt --version "3.6.8~ynh1" +then + # Add variables to .env config file + echo -e "\ +\n# Sub-URI\ +\nRAILS_RELATIVE_URL_ROOT=/\ +" >> "$config_file" + + # Apply Patch + if [ -f "$YNH_CWD/../sources/patches/app-00-add-path-url.patch" ] + then + pushd "$final_path/live" + patch --strip=1 < "$YNH_CWD/../sources/patches/app-00-add-path-url.patch" + popd + fi +fi + + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= diff --git a/sources/patches/app-00-add-path-url.patch b/sources/patches/app-00-add-path-url.patch new file mode 100644 index 0000000..92d073a --- /dev/null +++ b/sources/patches/app-00-add-path-url.patch @@ -0,0 +1,12 @@ +diff --git a/config.ru b/config.ru +index bd83b25..6b1bb50 100644 +--- a/config.ru ++++ b/config.ru +@@ -1,4 +1,6 @@ + # This file is used by Rack-based servers to start the application. + + require ::File.expand_path('../config/environment', __FILE__) +-run Rails.application ++map ENV['RAILS_RELATIVE_URL_ROOT'] || '/' do ++ run Rails.application ++end