-
Notifications
You must be signed in to change notification settings - Fork 2
/
entrypoint.sh
executable file
·51 lines (40 loc) · 1.63 KB
/
entrypoint.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
46
47
48
49
50
51
#!/bin/sh
# Replace env in app.*.js
for file in /usr/share/nginx/html/js/app.*.js;
do
echo "[Info] Processing $file ...";
# Use the existing JS file as template
if [ ! -f $file.tmpl.js ]; then
cp $file $file.tmpl.js
fi
envsubst '$VUE_APP_BASE_URI' < $file.tmpl.js > $file
cp $file $file.tmpl.js
envsubst '$VUE_APP_API_BASE_URL' < $file.tmpl.js > $file
cp $file $file.tmpl.js
envsubst '$VUE_APP_AVATAR_BASE_URL' < $file.tmpl.js > $file
done
# -------------
# CSP Rule
# -------------
NGINX_CONF_FILE="/etc/nginx/conf.d/default.conf"
INDEX_HTML_FILE="/usr/share/nginx/html/index.html";
# Add avatars url to csp
if [ -z "${VUE_APP_AVATAR_BASE_URL}" ]; then
echo "[Warn] VUE_APP_AVATAR_BASE_URL env value is not defined, it can cause problem on profile avatar image loading !"
else
sed -i "s~img-src~img-src $VUE_APP_AVATAR_BASE_URL~g" $NGINX_CONF_FILE
fi
# Replace env in index.html
echo "[Info] Processing $INDEX_HTML_FILE ...";
cp $INDEX_HTML_FILE $INDEX_HTML_FILE.tmp
HEAD_TAG="<\/head>"
# Add google analytics tag to head & csp
if [ -z "${VUE_APP_ANALYTICS_GOOGLE_TAG}" ]; then
echo "[Info] VUE_APP_ANALYTICS_GOOGLE_TAG env value is not defined";
else
GA_TAG='<script>window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;ga("create", "'$VUE_APP_ANALYTICS_GOOGLE_TAG'", "auto");ga("send", "pageview");<\/script><script async src="https:\/\/www.google-analytics.com\/analytics.js"><\/script>'
sed -i "s/$HEAD_TAG/$GA_TAG\n$HEAD_TAG/g" $INDEX_HTML_FILE
sed -i "s~script-src~script-src https://www.google-analytics.com~g" $NGINX_CONF_FILE
fi
echo "[Info] Starting Nginx ..."
nginx -g 'daemon off;'