Skip to content

Commit

Permalink
API Caching
Browse files Browse the repository at this point in the history
  • Loading branch information
wmuldergov committed Jan 26, 2024
1 parent 3eb5a25 commit 40c32a5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
17 changes: 17 additions & 0 deletions compose/frontend/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,30 @@ server {
server_name localhost;

access_log /dev/null;
proxy_cache_path /var/cache/nginx keys_zone=cache:50m;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}

proxy_cache cache;
# Caching data from the API
location /api/ {
proxy_ssl_server_name on;
proxy_pass ${ENVIRONMENT}-django;
proxy_connect_timeout 5s;
proxy_cache_background_update on;
proxy_cache_lock on;
proxy_cache_lock_age 10s;
proxy_cache_lock_timeout 10s;
proxy_cache_revalidate on;
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
proxy_cache_valid 200 1m;
add_header X-Proxy-Cache $upstream_cache_status;
}

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
Expand Down
14 changes: 14 additions & 0 deletions compose/frontend/entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,17 @@ echo -e "window.GEOCODER_API_AUTH_KEY='${REACT_APP_GEOCODER_API_AUTH_KEY}';" >>
echo -e "window.ROUTE_PLANNER='${REACT_APP_ROUTE_PLANNER}';" >> $MAIN
echo -e "window.ROUTE_PLANNER_KEY='${REACT_APP_ROUTE_PLANNER_KEY}';" >> $MAIN
echo -e "window.REPLAY_THE_DAY='${REACT_APP_REPLAY_THE_DAY}';" >> $MAIN

# Set the environment to be used for caching django content
sed -i "s~\$ENVIRONMENT~$ENVIRONMENT~g" /etc/nginx/conf.d/default.conf


#FOLLOWING SECTION IS TEMPORARY FOR THE PRIVATE BETA
# Check if $ENVIRONMENT is not set to "prod". If it is prod we want to keep these lines
if [ "$ENVIRONMENT" != "prod" ]; then
# Remove the specified lines from default.conf
sed -i '/auth_basic "Beta Site";/d' /etc/nginx/conf.d/default.conf
sed -i '/auth_basic_user_file \/etc\/apache2\/.htpasswd;/d' /etc/nginx/conf.d/default.conf
fi
#Copy the content of the secret into the .htpasswd file.
echo "$TEMP_AUTH_SECRET" >> /etc/apache2/.htpasswd

0 comments on commit 40c32a5

Please sign in to comment.