diff --git a/check_process b/check_process index 215ffde..9c48450 100644 --- a/check_process +++ b/check_process @@ -6,21 +6,21 @@ ;; Test complet ; Manifest domain="domain.tld" (DOMAIN) + path="/path" (PATH) is_public=1 (PUBLIC|public=1|private=0) ; Checks pkg_linter=1 - setup_sub_dir=0 + setup_sub_dir=1 setup_root=1 setup_nourl=0 setup_private=1 setup_public=1 upgrade=1 - upgrade=1 from_commit=d39e8118603e1cc7e00d1c414ad9b55da68bfc7a backup_restore=1 multi_instance=1 incorrect_path=1 port_already_use=0 - change_url=0 + change_url=1 ;;; Levels Level 1=auto Level 2=auto diff --git a/conf/.env b/conf/.env index a5c103e..7d7f328 100644 --- a/conf/.env +++ b/conf/.env @@ -8,7 +8,7 @@ PORT=__PORT__ DB_DIR=__FINALPATH__/distbin-db # The external URL -EXTERNAL_URL=https://__DOMAIN_URI__ +EXTERNAL_URL=https://__DOMAIN_URI__/ # The internal URL INTERNAL_URL=http://localhost:__PORT__/ diff --git a/conf/nginx.conf b/conf/nginx.conf index 7cf6397..677303b 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -7,8 +7,12 @@ location __PATH__/ { } proxy_pass http://127.0.0.1:__PORT__/; - proxy_set_header Host $host; - # proxy_buffering off; + proxy_pass_request_headers on; + proxy_redirect ~^/(.*) $scheme://$http_host__PATH__/$1; + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; # Include SSOWAT user panel. include conf.d/yunohost_panel.conf.inc; diff --git a/manifest.json b/manifest.json index e2d1084..038e16a 100644 --- a/manifest.json +++ b/manifest.json @@ -30,6 +30,16 @@ }, "example": "distbin.example.com" }, + { + "name": "path", + "type": "path", + "ask": { + "en": "Choose a path for distbin", + "fr": "Choisissez un chemin pour distbin" + }, + "example": "/distbin", + "default": "/distbin" + }, { "name": "is_public", "type": "boolean", diff --git a/scripts/change_url b/scripts/change_url index 3d678fc..afe76c7 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -7,6 +7,7 @@ #================================================= source _common.sh +source ynh_systemd_action source /usr/share/yunohost/helpers #================================================= @@ -17,7 +18,7 @@ old_domain=$YNH_APP_OLD_DOMAIN old_path=$YNH_APP_OLD_PATH new_domain=$YNH_APP_NEW_DOMAIN -new_path="/" +new_path=$YNH_APP_NEW_PATH app=$YNH_APP_INSTANCE_NAME @@ -32,6 +33,7 @@ final_path=$(ynh_app_setting_get $app final_path) # Add settings here as needed by your application #db_name=$(ynh_app_setting_get "$app" db_name) #db_pwd=$(ynh_app_setting_get $app db_pwd) +port=$(ynh_app_setting_get $app port) #================================================= # CHECK THE SYNTAX OF THE PATHS @@ -95,14 +97,22 @@ fi # STOP SERVICE #================================================= -ynh_systemd_action --action=stop --service_name=$app +ynh_systemd_action --action=stop --service_name=$app --log_path=systemd --line_match="Stopped Distbin Service" #================================================= # MODIFY A CONFIG FILE #================================================= # Change the URL in the configuration file -ynh_replace_string "EXTERNAL_URL=.*" "EXTERNAL_URL=https://$new_domain$new_path" "$final_path/.env" + +if [ "$new_path" == "/" ] +then + new_domain_uri="$new_domain" +else + new_domain_uri="$new_domain$new_path" +fi + +ynh_replace_string "EXTERNAL_URL=.*" "EXTERNAL_URL=https://$new_domain_uri/" "$final_path/.env" ### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. ### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. @@ -114,8 +124,7 @@ ynh_store_file_checksum "$final_path/.env" # START SERVICE #================================================= -ynh_systemd_action --action=start --service_name=$app - +ynh_systemd_action --action=start --service_name=$app --line_match="http" #================================================= # GENERIC FINALISATION diff --git a/scripts/install b/scripts/install index e34eb10..9eca9b9 100644 --- a/scripts/install +++ b/scripts/install @@ -26,7 +26,7 @@ ynh_abort_if_errors #================================================= domain=$YNH_APP_ARG_DOMAIN -path_url="/" +path_url=$YNH_APP_ARG_PATH #admin=$YNH_APP_ARG_ADMIN is_public=$YNH_APP_ARG_IS_PUBLIC #language=$YNH_APP_ARG_LANGUAGE @@ -196,10 +196,16 @@ ynh_add_systemd_config ### (It's compatible with sed regular expressions syntax) cp "../conf/.env" "$final_path/.env" +if [ "$path_url" == "/" ] +then + domain_uri="$domain" +else + domain_uri="$domain$path_url" +fi ynh_replace_string "__NODEJS_PATH__" "$nodejs_path" "$final_path/.env" ynh_replace_string "__PORT__" "$port" "$final_path/.env" -ynh_replace_string "__DOMAIN_URI__" "$domain$path_url" "$final_path/.env" +ynh_replace_string "__DOMAIN_URI__" "$domain_uri" "$final_path/.env" ynh_replace_string "__FINALPATH__" "$final_path" "$final_path/.env" #================================================= @@ -281,7 +287,7 @@ systemctl reload nginx # START SERVICE #================================================= -ynh_systemd_action --action=start --service_name=$app --log_path=systemd --line_match="Started Distbin Service" +ynh_systemd_action --action=start --service_name=$app --line_match="http" #================================================= # END OF SCRIPT