diff --git a/resources/aliases b/resources/aliases index 2600a481d..5b5720c8c 100644 --- a/resources/aliases +++ b/resources/aliases @@ -74,6 +74,18 @@ function serve-silverstripe() { fi } +function serve-spa() { + if [[ "$1" && "$2" ]] + then + sudo dos2unix /vagrant/scripts/serve-spa.sh + sudo bash /vagrant/scripts/serve-spa.sh "$1" "$2" 80 + else + echo "Error: missing required parameters." + echo "Usage: " + echo " serve-spa domain path" + fi +} + function serve-statamic() { if [[ "$1" && "$2" ]] then diff --git a/scripts/serve-spa.sh b/scripts/serve-spa.sh new file mode 100644 index 000000000..0b64bef92 --- /dev/null +++ b/scripts/serve-spa.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +block="server { + listen ${3:-80}; + listen ${4:-443} ssl http2; + server_name $1; + root \"$2\"; + + index index.html; + + charset utf-8; + + location / { + try_files \$uri \$uri/ /index.html; + } + + location = /favicon.ico { access_log off; log_not_found off; } + location = /robots.txt { access_log off; log_not_found off; } + + access_log off; + error_log /var/log/nginx/$1-error.log error; + + sendfile off; + + client_max_body_size 100m; + + location ~ /\.ht { + deny all; + } + + ssl_certificate /etc/nginx/ssl/$1.crt; + ssl_certificate_key /etc/nginx/ssl/$1.key; +} +" + +echo "$block" > "/etc/nginx/sites-available/$1" +ln -fs "/etc/nginx/sites-available/$1" "/etc/nginx/sites-enabled/$1"