From d180592b9dca960ff102947b37429c2e8727cfab Mon Sep 17 00:00:00 2001 From: Antoine Lima Date: Sun, 10 Mar 2024 22:53:44 +0100 Subject: [PATCH] Add nodejs support in the config panel --- config_panel.toml | 9 +++++++++ scripts/config | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/config_panel.toml b/config_panel.toml index b229f0f..3aa910d 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -52,6 +52,15 @@ name = "My Webapp configuration" default = "low" help = "low: Personal usage, behind the sso. No RAM footprint when not used, but the impact on the processor can be high if many users are using the service.
medium: Low usage, few people or/and publicly accessible. Low RAM footprint, medium processor footprint when used.
high: High usage, frequently visited website. High RAM footprint, but lower on processor usage and quickly responding." + [main.nodejs] + name = "NodeJS configuration" + + [main.nodejs.nodeversion] + ask = "NodeJS version" + type = "select" + choices = ["none", "18", "20", "21"] + default = "none" + # TODO: Add protected_path as tags, which are created as permission "label (path)", so admin can protect a specific path # [main.permissions] # [main.permissions.proteced_path] diff --git a/scripts/config b/scripts/config index 21b6f17..4089396 100644 --- a/scripts/config +++ b/scripts/config @@ -105,6 +105,11 @@ ynh_app_config_validate() { exit 0 fi fi + + if [ "${changed[nodeversion]}" == "true" ] && [ $nodeversion != "none" ] && [ $phpversion != "none" ] + then + ynh_die --message="You cannot have both PHP and NodeJS, choose only one." + fi } ynh_app_config_apply() { @@ -152,6 +157,19 @@ ynh_app_config_apply() { then ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint fi + + if [ "${changed[nodeversion]}" == "true" ] + then + if [ "$nodeversion" != "none" ] + then + ynh_install_nodejs --nodejs_version=$nodeversion + ynh_use_nodejs + export port=$(ynh_app_setting_get $app port) + ynh_setup_my_nodeapp --app=$app --install_dir=$install_dir + else + ynh_remove_my_nodeapp --app=$app + fi + fi } ynh_app_config_run $1