Skip to content

Commit

Permalink
Merge pull request #1 from RedVentures/feature/abstract-cache-invalid…
Browse files Browse the repository at this point in the history
…ation-endpoints

Abstract cache invalidation endpoints
  • Loading branch information
carlosesilva committed Jun 10, 2019
2 parents 8fb550b + 02d3d25 commit ed4e598
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions inc/cloudfront.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ function cloudfront_cache_invalidator() {
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', () => {
// Some global vars
const cacheBaseUrl = 'https://at38idql6j.execute-api.us-east-1.amazonaws.com';
const gatewayStage = 'development';
const cacheInvalidationUrl = `${cacheBaseUrl}/${gatewayStage}/clearcache`;
const cacheStatusUrl = `${cacheBaseUrl}/${gatewayStage}/status`;
const cacheInvalidationEndpoint = '<?php echo get_field('cache_invalidation_endpoint', 'option' ); ?>';
const cacheInvalidationStatusEndpoint = '<?php echo get_field('cache_invalidation_status_endpoint', 'option' ); ?>';
let interval;

// DOM Elements
Expand All @@ -46,7 +44,7 @@ function cloudfront_cache_invalidator() {
loadingText.style.display = 'block';

// Fire off the request
fetch(cacheInvalidationUrl)
fetch(cacheInvalidationEndpoint)
.then(response => response.json())
.then(response => {
if (!response.invalidationId) {
Expand All @@ -71,7 +69,7 @@ function cloudfront_cache_invalidator() {
// Checks the invalidation status. Once it's complete, will notify the user.
const checkInvalidation = (invalidationId) => {
// If we have an invalidationId, go ahead and fire off the request
var url = `${cacheStatusUrl}/${invalidationId}`;
var url = `${cacheInvalidationStatusEndpoint}/${invalidationId}`;
fetch(url)
.then(response => response.json())
.then(response => {
Expand Down

0 comments on commit ed4e598

Please sign in to comment.