Skip to content

Commit

Permalink
Refactor to SERVER_PATH_PREFIX
Browse files Browse the repository at this point in the history
The server path prefix is always set, either to `/` (no relative url
configured), or to `/<relative url>/`.

As we need a non-trailing slash for proxy and relative root, we need to
hack around a little.
  • Loading branch information
oliverguenther committed Dec 8, 2015
1 parent 0d0e97f commit 36b5131
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 26 deletions.
2 changes: 1 addition & 1 deletion bin/configure
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ input_server_params() {
}

input_subfolder_params() {
wiz_put "server/subfolder_location"
wiz_put "server/server_path_prefix"

if wiz_ask ; then
STATE="server_ssl"
Expand Down
49 changes: 36 additions & 13 deletions bin/postinstall
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,39 @@ enable_apache2_vhost_include() {
fi
}

##
# Cleans and sets the server path prefix from user input.
# Ensures that:
#
# 1. The server prefix always has a trailing slash and leading.
#
# 2. The server prefix is set to '/' when no configuration was made.
#
# Exposes the prefix through SERVER_PATH_PREFIX.
build_server_path_prefix() {
server_path_prefix="$(wiz_get server/server_path_prefix)"

# Configure subfolder location
if [ -z "$server_path_prefix" ]; then
server_path_prefix="/"
server_path_prefix_noslash="/"
else
# Force leading slash if missing
leading=${server_path_prefix:0:1}
[[ $leading != "/" ]] && server_path_prefix="/${server_path_prefix}"; :

# Force trailing slash if missing
trailing=${server_path_prefix:length-1:1}
[[ $trailing != "/" ]] && server_path_prefix="${server_path_prefix}/"; :

server_path_prefix_noslash="${server_path_prefix:0:length-1}"
fi

${APP_NAME} config:set SERVER_PATH_PREFIX="${server_path_prefix}"
}

configure_apache2_server() {
local web_hostname="$(wiz_get server/hostname)"
local subfolder_location="$(wiz_get server/subfolder_location)"
local web_ssl="$(wiz_get server/ssl)"
local web_ssl_cert="$(wiz_get server/ssl_cert)"
local web_ssl_key="$(wiz_get server/ssl_key)"
Expand All @@ -140,15 +170,6 @@ configure_apache2_server() {
# so that the folder is not empty
echo "# placeholder, do not remove" > "$SERVER_INCLUDES_DIR/placeholder.conf"

# Configure subfolder location
if [ -n "$subfolder_location" ]; then
# Force leading slash if missing
leading=${subfolder_location:0:1}
[[ $leading != "/" ]] && subfolder_location="/${subfolder_location}"; :

${APP_NAME} config:set SUBFOLDER_LOCATION="${subfolder_location}"
fi

if [ "$OSFAMILY" = "redhat" ] ; then
web_user="apache"
elif [ "$OSFAMILY" = "suse" ] ; then
Expand Down Expand Up @@ -180,8 +201,8 @@ configure_apache2_server() {
sed -i "s|_SSL_PORT_|${web_ssl_port}|g" ${vhost_file}
sed -i "s|_APP_PORT_|${web_app_port}|g" ${vhost_file}
sed -i "s|_APP_NAME_|${APP_NAME}|g" ${vhost_file}
sed -i "s|_APP_SUBFOLDER_|${subfolder_location}|g" ${vhost_file}
sed -i "s|_APP_SUBFOLDER_OR_ROOT_|${subfolder_location:-"/"}|g" ${vhost_file}
sed -i "s|_SERVER_PATH_PREFIX_NOSLASH_|${server_path_prefix_noslash}|g" ${vhost_file}
sed -i "s|_SERVER_PATH_PREFIX_|${server_path_prefix}|g" ${vhost_file}

# copy vhost-level includes
for conf in ${vhost_includes}; do
Expand All @@ -194,7 +215,8 @@ configure_apache2_server() {
sed -i "s|_SSL_CERT_|${web_ssl_cert}|g" ${tmpfile}
sed -i "s|_SSL_KEY_|${web_ssl_key}|g" ${tmpfile}
sed -i "s|_SSL_CA_|${web_ssl_ca}|g" ${tmpfile}
sed -i "s|_APP_SUBFOLDER_|${subfolder_location}|g" ${vhost_file}
sed -i "s|_APP_NAME_|${APP_NAME}|g" ${tmpfile}
sed -i "s|_SERVER_PATH_PREFIX_|${server_path_prefix}|g" ${tmpfile}

mv -f "$tmpfile" "$dst"
enable_apache2_vhost_include "$dst"
Expand Down Expand Up @@ -227,6 +249,7 @@ case "$(wiz_get "server/autoinstall")" in
"skip")
;;
"install")
build_server_path_prefix
configure_apache2_server
;;
*)
Expand Down
4 changes: 2 additions & 2 deletions conf/includes/vhost/assets.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
</IfModule>
</Directory>

ProxyPass _APP_SUBFOLDER_/assets/ !
ProxyPass _SERVER_PATH_PREFIX_assets/ !

<Location _APP_SUBFOLDER_/assets/>
<Location _SERVER_PATH_PREFIX_assets/>
ExpiresActive On ExpiresDefault "access plus 1 year"
</Location>
2 changes: 1 addition & 1 deletion conf/includes/vhost/sys.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<LocationMatch "^_APP_SUBFOLDER_/sys">
<LocationMatch "^_SERVER_PATH_PREFIX_sys">
<IfModule mod_authz_core.c>
Require local
</IfModule>
Expand Down
4 changes: 2 additions & 2 deletions conf/web-raw
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Include /etc/_APP_NAME_/addons/apache2/includes/server/*.conf

Include /etc/_APP_NAME_/addons/apache2/includes/vhost/*.conf

ProxyPass _APP_SUBFOLDER_OR_ROOT_ http://127.0.0.1:_APP_PORT__APP_SUBFOLDER_/ retry=0
ProxyPassReverse _APP_SUBFOLDER_OR_ROOT_ http://127.0.0.1:_APP_PORT__APP_SUBFOLDER_/
ProxyPass _SERVER_PATH_PREFIX_NOSLASH_ http://127.0.0.1:_APP_PORT__SERVER_PATH_PREFIX_ retry=0
ProxyPassReverse _SERVER_PATH_PREFIX_NOSLASH_ http://127.0.0.1:_APP_PORT__SERVER_PATH_PREFIX_

</VirtualHost>
8 changes: 4 additions & 4 deletions conf/web-ssl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Include /etc/_APP_NAME_/addons/apache2/includes/server/*.conf

<VirtualHost *:_RAW_PORT_>
ServerName _HOSTNAME_
Redirect permanent / https://_HOSTNAME_:_SSL_PORT__APP_SUBFOLDER_
Redirect permanent _SERVER_PATH_PREFIX_ https://_HOSTNAME_:_SSL_PORT__SERVER_PATH_PREFIX_
</VirtualHost>

<VirtualHost *:_SSL_PORT_>
Expand All @@ -12,7 +12,7 @@ Include /etc/_APP_NAME_/addons/apache2/includes/server/*.conf
ProxyRequests off

Include /etc/_APP_NAME_/addons/apache2/includes/vhost/*.conf

ProxyPass _APP_SUBFOLDER_OR_ROOT_ http://127.0.0.1:_APP_PORT__APP_SUBFOLDER_/ retry=0
ProxyPassReverse _APP_SUBFOLDER_OR_ROOT_ http://127.0.0.1:_APP_PORT__APP_SUBFOLDER_/
ProxyPass _SERVER_PATH_PREFIX_NOSLASH_ http://127.0.0.1:_APP_PORT__SERVER_PATH_PREFIX_ retry=0
ProxyPassReverse _SERVER_PATH_PREFIX_NOSLASH_ http://127.0.0.1:_APP_PORT__SERVER_PATH_PREFIX_
</VirtualHost>
6 changes: 3 additions & 3 deletions templates
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ Default: www.example.com
Description: Your fully qualified domain name:
Enter the fully qualified domain name (FQDN), where this server can be reached.

Template: server/subfolder_location
Template: server/server_path_prefix
Type: string
Description: Subdirectory location:
If you wish to deploy to a subdirectory (e.g., example.org/openproject), enter the location with a leading slash here.
Description: Server path prefix:
If you wish to deploy to a path prefix (e.g., example.org/openproject), enter the prefix with a leading slash.
.
If you keep this input empty, _APP_NAME_ is installed to the root of your domain.

Expand Down

0 comments on commit 36b5131

Please sign in to comment.