Skip to content

Commit

Permalink
Production , env config, nginx add csp headers
Browse files Browse the repository at this point in the history
  • Loading branch information
yassinrais committed Feb 4, 2022
1 parent 6c05f5c commit 83b4629
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 20 deletions.
17 changes: 5 additions & 12 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Replace env in app.*.js
for file in /usr/share/nginx/html/js/app.*.js;
do
echo "Processing $file ...";
echo "[Info] Processing $file ...";

# Use the existing JS file as template
if [ ! -f $file.tmpl.js ]; then
Expand All @@ -16,26 +16,19 @@ do
done

# Replace env in index.html
if [ -z "${VUE_APP_CSP_HOSTS}" ]]; then
echo "VUE_APP_CSP_HOSTS env value is required";
exit 1;
fi

file="/usr/share/nginx/html/index.html";
echo "Processing $file ...";
cp $file $file.tmp

envsubst '$VUE_APP_CSP_HOSTS' < $file.tmp > $file
echo "[Info] Processing $file ...";
cp $file $file.tmp

head_tag="<\/head>"
# Inject extra headers
if [ -z "${VUE_APP_ANALYTICS_GOOGLE_TAG}" ]; then
echo "VUE_APP_ANALYTICS_GOOGLE_TAG env value is not defined";
echo "[Info] VUE_APP_ANALYTICS_GOOGLE_TAG env value is not defined";
else
# Inject google analytics
g_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>\n'$head_tag
sed -i "s/$head_tag/$g_tag/g" $file
fi

echo "Starting Nginx"
echo "[Info] Starting Nginx ..."
nginx -g 'daemon off;'
7 changes: 7 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ server {
gzip_static on;
gzip_min_length 500;


add_header X-Frame-Options "DENY";
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header Content-Security-Policy "default-src 'self'; font-src *; script-src 'unsafe-eval' 'self';style-src 'self' 'unsafe-inline' fonts.googleapis.com; font-src *; object-src 'none'; base-uri 'self'; form-action 'self'; img-src * data:;";

location / {
try_files $uri $uri/ @rewrites;
}

location @rewrites {

rewrite ^(.+)$ /index.html last;
}

Expand Down
4 changes: 0 additions & 4 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<meta http-equiv="Content-Security-Policy" content="img-src cdnjs.cloudflare.com $VUE_APP_CSP_HOSTS 'self' data:;">
<meta http-equiv="Content-Security-Policy"
content="script-src 'unsafe-eval' 'self';style-src 'self' 'unsafe-inline' fonts.googleapis.com;">
<meta http-equiv="Content-Security-Policy" content="object-src 'none'; base-uri 'self'; form-action 'self'">

<title>Saferwall</title>

Expand Down
3 changes: 1 addition & 2 deletions src/common/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default class Config {
static get CONFIG() {
return {
baseURI: '$VUE_APP_BASE_URL',
baseURI: '$VUE_APP_BASE_URI',
apiURL: '$VUE_APP_API_BASE_URL',
avatarURL: '$VUE_APP_AVATAR_BASE_URL',
isProd: process.env.NODE_ENV === 'production'
Expand All @@ -15,7 +15,6 @@ export default class Config {
}

const value = this.CONFIG[name]

if (!value) {
console.log(`Configuration: Value for "${name}" is not defined`)
return
Expand Down
4 changes: 2 additions & 2 deletions src/services/axios/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios'
import APP_CONFIGS from "@/common/config";
import Config from "@/common/config";

export default axios.create({
baseURL: APP_CONFIGS.apiURL,
baseURL: Config.value('apiURL'),
withCredentials: true
})

0 comments on commit 83b4629

Please sign in to comment.