Skip to content

Commit f67b16c

Browse files
committed
Merge branch 'feature/dynamic-api-paths'
2 parents 693d59e + 5289d0e commit f67b16c

File tree

24 files changed

+196
-12
lines changed

24 files changed

+196
-12
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ Images with `nginx` can be configured using the following environment variables.
1818
|-----------------|---------|-------------|---------|
1919
| NGINX_CORS_ORIGINS | Every run | Comma separated list of hostnames (without `https://`) | `*` |
2020

21+
### Paths
22+
23+
| Environment Key | Applied | Description | Default |
24+
|-----------------|---------|-------------|---------|
25+
| NGINX_API_PATHS | Every run | Comma separated list of paths (without `/`), pointed to the `@api_backend` bucket. Note to only use this on images that have such a backend. | |
26+
2127
### Robots
2228

2329
| Environment Key | Applied | Description | Default |
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env sh
2+
3+
set -euo pipefail
4+
5+
# Configure nginx CORS rules based on ENV vars
6+
#
7+
# Inputs:
8+
# - NGINX_API_PATHS: defaults to '' (empty list)
9+
10+
# Set defaults & clean up (normalize, trim, …)
11+
NGINX_CONFIG_FILE=/etc/nginx/site-mods-enabled.d/generated-api-paths.conf
12+
NGINX_API_PATHS=$(echo "${NGINX_API_PATHS:-}" \
13+
| sed 's/,/ /g; s/^ *//; s/ *$//; s/ */ /g')
14+
15+
# Check nginx structure
16+
if [ ! -d /etc/nginx/site-mods-enabled.d/ ]; then
17+
exit 0
18+
fi
19+
20+
# Generate location blocks
21+
echo "Nginx: configuring API paths with '${NGINX_API_PATHS}'…"
22+
echo "# Point API paths to API bucket" > "${NGINX_CONFIG_FILE}"
23+
for item in $NGINX_API_PATHS; do
24+
echo "location ~ ^/${item}/ { try_files \$uri @api_backend; }" >> "${NGINX_CONFIG_FILE}"
25+
done

nuxt-base/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ COPY config/s6-overlay /etc/s6-overlay/s6-rc.d/
1919
# - init
2020
COPY scripts/ /scripts/
2121

22+
# Defaults
23+
ENV NGINX_API_PATHS=api
24+
2225
#
2326
# --- Variant: Unsecured ---
2427
#

nuxt-base/config/nginx/http.d/default.conf

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ server {
1111
root $root;
1212

1313
# Serve files (and nice URLs)
14-
location ~ ^/api/ {
15-
try_files $uri @api_backend;
16-
}
14+
# Note: API location generated by script using `NGINX_API_PATHS`
1715
location / {
1816
try_files $uri $uri/index.html $uri.html @web_backend;
1917
}

payload-base/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ COPY config/s6-overlay /etc/s6-overlay/s6-rc.d/
1919
# - init
2020
COPY scripts/ /scripts/
2121

22+
# Defaults
23+
ENV NGINX_API_PATHS=api
24+
2225
#
2326
# --- Variant: Default ---
2427
#

payload-base/config/nginx/http.d/default.conf

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ server {
1111
root $root;
1212

1313
# Serve files (and nice URLs)
14-
location ~ ^/api/ {
15-
try_files $uri @api_backend;
16-
}
14+
# Note: API location generated by script using `NGINX_API_PATHS`
1715
location / {
1816
try_files $uri $uri/index.html $uri.html @web_backend;
1917
}

php-base/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ COPY config/s6-overlay /etc/s6-overlay/s6-rc.d/
5252
# - init
5353
COPY scripts/ /scripts/
5454

55+
# Defaults
56+
ENV NGINX_API_PATHS=api,oauth,livewire
57+
5558
#
5659
# --- Variant: Octane ---
5760
#

php-base/config/nginx/http.d/default-fpm.conf

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ server {
1313
root $root;
1414

1515
# Serve files (and nice URLs)
16-
location ~ ^/(api|oauth|livewire)/ {
17-
try_files $uri @api_backend;
18-
}
16+
# Note: API location generated by script using `NGINX_API_PATHS`
1917
location / {
2018
try_files $uri @web_backend;
2119
}

php-base/config/nginx/http.d/default-octane.conf

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ server {
1313
root $root;
1414

1515
# Serve files (and nice URLs)
16-
location ~ ^/(api|oauth|livewire)/ {
17-
try_files $uri @api_backend;
18-
}
16+
# Note: API location generated by script using `NGINX_API_PATHS`
1917
location / {
2018
try_files $uri @web_backend;
2119
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NGINX_API_PATHS=api,custom-api

0 commit comments

Comments
 (0)