Skip to content

Commit

Permalink
remove gzip from events endpoint to fix sse (#103)
Browse files Browse the repository at this point in the history
* remove gzip from events endpoint to fix sse

* revert docker compose file
  • Loading branch information
cmintey authored Jan 27, 2024
1 parent 0ec1f5d commit b5eb6cb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
14 changes: 12 additions & 2 deletions Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,25 @@
path *.ico *.css *.js *.gif *.jpg *.jpeg *.png *.svg *.woff *.woff2 *.webp
}

@not_sse {
not path /api/events
}

# Handles User Images
handle_path /api/assets/* {
header @static Cache-Control max-age=31536000
root * /usr/src/app/uploads/
file_server
}

encode gzip
reverse_proxy :3000
# gzip makes sse not work so use it for everything but the events api
encode @not_sse {
gzip
}

reverse_proxy :3000 {
flush_interval -1
}
}


1 change: 0 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ services:
app:
container_name: wishlist-app
image: ghcr.io/cmintey/wishlist
build: .
ports:
- 3280:3280
volumes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ export const GET = (async () => {
subscribeToEvent(itemEmitter, SSEvents.item.delete);
return new Response(readable, {
headers: {
"cache-control": "no-cache",
"content-type": "text/event-stream"
"Cache-Control": "no-cache",
"Content-Type": "text/event-stream",
"X-Accel-Buffering": "no"
}
});
}) satisfies RequestHandler;
2 changes: 1 addition & 1 deletion src/routes/wishlists/[username]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
onDestroy(() => eventSource?.close());
const subscribeToEvents = () => {
eventSource = new EventSource("/api/items/updates");
eventSource = new EventSource("/api/events");
eventSource.addEventListener(SSEvents.item.update, (e) => {
const message = JSON.parse(e.data) as Item;
updateItems(message);
Expand Down

0 comments on commit b5eb6cb

Please sign in to comment.