Skip to content

Commit

Permalink
DBC22-1656: Adding caching for APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
wmuldergov committed Jan 26, 2024
1 parent fb8d9f2 commit 76fb57c
Show file tree
Hide file tree
Showing 2 changed files with 20 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,6 +4,7 @@ server {
server_name localhost;

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

location / {
root /usr/share/nginx/html;
Expand All @@ -13,6 +14,22 @@ server {
auth_basic_user_file /etc/apache2/.htpasswd;
}

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
3 changes: 3 additions & 0 deletions compose/frontend/entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ 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
Expand Down

0 comments on commit 76fb57c

Please sign in to comment.