-
Notifications
You must be signed in to change notification settings - Fork 64
/
start.sh
executable file
·45 lines (37 loc) · 892 Bytes
/
start.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
if [ -z "$REDIRECT_TYPE" ]; then
REDIRECT_TYPE="permanent"
fi
if [ -z "$REDIRECT_TARGET" ]; then
echo "Redirect target variable not set (REDIRECT_TARGET)"
exit 1
else
# Add http if not set
if ! [[ $REDIRECT_TARGET =~ ^https?:// ]]; then
REDIRECT_TARGET="http://$REDIRECT_TARGET"
fi
fi
# Default to 80
LISTEN="80"
# Listen to PORT variable given on Cloud Run Context
if [ ! -z "$PORT" ]; then
LISTEN="$PORT"
fi
: ${RETAIN_PATH:='true'}
if [ "$RETAIN_PATH" = "true" ]; then
cat <<EOF > /etc/nginx/conf.d/default.conf
server {
listen ${LISTEN};
rewrite ^(.*)\$ ${REDIRECT_TARGET}\$1 ${REDIRECT_TYPE};
}
EOF
else
cat <<EOF > /etc/nginx/conf.d/default.conf
server {
listen ${LISTEN};
rewrite ^(.*)\$ ${REDIRECT_TARGET} ${REDIRECT_TYPE};
}
EOF
fi
echo "Listening to $LISTEN, Redirecting HTTP requests to ${REDIRECT_TARGET}..."
exec nginx -g "daemon off;"