Add nodejs support in the config panel

This commit is contained in:
Antoine Lima 2024-03-10 22:53:44 +01:00
parent 1510b03634
commit d180592b9d
No known key found for this signature in database
GPG key ID: 5D1E65E3DEB73410
2 changed files with 27 additions and 0 deletions

View file

@ -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.<br>medium: Low usage, few people or/and publicly accessible. Low RAM footprint, medium processor footprint when used.<br>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]

View file

@ -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