Skip to content

Commit 52d13b2

Browse files
committed
add PHP server prepend file as codespaces uses HTTP_X_FORWARDED_X
1 parent 4097d93 commit 52d13b2

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

.devcontainer/build.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ php -d memory_limit=512M ../phd/render.php \
2525
# Restart any existing server, then launch the new one in its own session so
2626
# Ctrl+C in the debug terminal only kills the log tail below. The server keeps
2727
# running until the next build replaces it (or the container shuts down).
28+
#
29+
# auto_prepend_file rewrites $_SERVER from the request's Host header so the PHP
30+
# format's $MYSITE-built URLs work behind Codespaces / other port forwarders.
2831
LOG="/tmp/php-server-${FORMAT}.log"
2932
pkill -f 'php -S 0.0.0.0:8080' 2>/dev/null || true
30-
setsid nohup php -S 0.0.0.0:8080 -t "$DOCROOT" \
33+
setsid nohup php -d "auto_prepend_file=$PREPEND" -S 0.0.0.0:8080 -t "$DOCROOT" \
3134
>"$LOG" 2>&1 </dev/null &
3235
SERVER_PID=$!
3336

.devcontainer/server-prepend.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
// This file rewrites $_SERVER from the request's Host header so the PHP
4+
// format's $MYSITE-built URLs work behind Codespaces / other port forwarders.
5+
6+
$forwardedHttps = ($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '') === 'https';
7+
$hostHeader = $_SERVER['HTTP_X_FORWARDED_HOST'] ?? $_SERVER['HTTP_HOST'] ?? '';
8+
9+
if ($hostHeader !== '') {
10+
$_SERVER['HTTP_HOST'] = $hostHeader;
11+
}
12+
13+
if ($forwardedHttps) {
14+
$_SERVER['HTTPS'] = 'on';
15+
}

0 commit comments

Comments
 (0)