Reality123b commited on
Commit
ff7cf8f
·
verified ·
1 Parent(s): da538ce

Create startup.sh

Browse files
Files changed (1) hide show
  1. startup.sh +27 -0
startup.sh ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+
3
+ # This script is run when the container starts.
4
+ # It injects the API_KEY (expected to be an environment variable at runtime)
5
+ # into a JavaScript file, then starts Nginx.
6
+
7
+ CONFIG_JS_PATH="/usr/share/nginx/html/config.js"
8
+
9
+ echo "Startup script running..."
10
+ echo "Attempting to write API key to $CONFIG_JS_PATH"
11
+
12
+ if [ -z "$API_KEY" ]; then
13
+ echo "WARNING: API_KEY environment variable is not set or is empty at runtime!" >&2
14
+ # Create a config that indicates the key is missing, so the frontend can handle it gracefully.
15
+ echo "window.MY_API_KEY = null; console.error('RUNTIME WARNING: API Key was not found in the environment when the container started.');" > "$CONFIG_JS_PATH"
16
+ echo "Wrote null API Key to $CONFIG_JS_PATH"
17
+ else
18
+ # Escape single quotes in API_KEY to prevent breaking the JS string.
19
+ # sed "s/'/'\\\\''/g" replaces ' with '\''
20
+ ESCAPED_API_KEY=$(echo "$API_KEY" | sed "s/'/'\\\\''/g")
21
+ echo "window.MY_API_KEY = '${ESCAPED_API_KEY}';" > "$CONFIG_JS_PATH"
22
+ echo "API Key successfully written to $CONFIG_JS_PATH"
23
+ fi
24
+
25
+ echo "Starting Nginx..."
26
+ # Start Nginx in the foreground, so the container keeps running.
27
+ nginx -g 'daemon off;'