Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove gzip from events endpoint to fix sse #103

Merged
merged 2 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading