Skip to content

Commit

Permalink
merge fix
Browse files Browse the repository at this point in the history
  • Loading branch information
markkelnar committed Aug 23, 2023
2 parents acbed08 + 39a56a6 commit 88672b7
Show file tree
Hide file tree
Showing 5 changed files with 245 additions and 75 deletions.
100 changes: 76 additions & 24 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 10 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
version: '3.3'

services:
varnish:
image: varnish:7.3
container_name: varnish
volumes:
- "./docker/varnish/default.vcl:/etc/varnish/default.vcl"
ports:
- "8081:80"
depends_on:
- "app"

app:
depends_on:
- app_db
Expand All @@ -16,17 +26,13 @@ services:
USING_XDEBUG: ${USING_XDEBUG:-}
ports:
- '8091:80'
networks:
local:

app_db:
image: mariadb:10.11
env_file:
- .env.dist
ports:
- '3306'
networks:
local:

testing:
depends_on:
Expand All @@ -42,18 +48,10 @@ services:
environment:
WP_URL: http://localhost
USING_XDEBUG: ${USING_XDEBUG:-}
networks:
local:

testing_db:
image: mariadb:10.11
env_file:
- .env.testing
ports:
- '3306'
networks:
local:


networks:
local:
49 changes: 49 additions & 0 deletions docker/varnish/default.vcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
vcl 4.1;

import xkey;

backend default {
.host = "app";
.port = "80";
}

sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT: " + obj.hits;
} else {
set resp.http.X-Cache = "MISS";
}
}

sub vcl_recv {

set req.http.host = "localhost:8091";

if (req.method == "PURGE_GRAPHQL") {
set req.http.n-gone = 0;

if (req.http.GraphQL-Purge-Keys && req.http.GraphQL-URL ) {
set req.http.xkeyPrefix = req.http.GraphQL-URL;

# replace commas with spaces
set req.http.cleanPurgeKeys = regsuball(req.http.GraphQL-Purge-Keys, "(\,+),?", " ");

# find all strings separated by space and add the host as a prefix.
set req.http.purgeKeys = regsuball(req.http.cleanPurgeKeys, "(\S+),?", req.http.xkeyPrefix + ":\1");

# call xkey.purge on the keys sent in the GraphQL-Purge-Keys header(s)
set req.http.n-gone = xkey.purge( req.http.purgeKeys );
}

# Return 200, reason showing how many queries were invalidated
return (synth(200, "Invalidated GraphQL Queries: "+req.http.purgeKeys+" "+req.http.n-gone));
}
}

sub vcl_backend_response {
if ( beresp.http.X-GraphQL-Keys ) {

set beresp.http.xkeyPrefix = beresp.http.X-GraphQL-URL;
set beresp.http.xkey = regsuball(beresp.http.X-GraphQL-Keys, "(\S+),?", beresp.http.xkeyPrefix + ":\1");
}
}
Loading

0 comments on commit 88672b7

Please sign in to comment.