From 0624b13a68755af6b35fdc7c274db41bcf126866 Mon Sep 17 00:00:00 2001 From: Jordan Owens Date: Mon, 31 Aug 2020 14:22:44 -0400 Subject: [PATCH] Update streaming example --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2db8ba5e..07afea36 100644 --- a/README.md +++ b/README.md @@ -1695,7 +1695,7 @@ require 'sinatra/base' class App < Sinatra::Base connections = [] - get '/subscribe' do + get '/subscribe', provides: 'text/event-stream' do # register a client's interest in server events stream(:keep_open) do |out| connections << out @@ -1704,17 +1704,16 @@ class App < Sinatra::Base end end - post '/:message' do + post '/' do connections.each do |out| # notify client that a new message has arrived - out << params['message'] << "\n" + out << "data: #{params[:msg]}\n\n" # indicate client to connect again out.close end - # acknowledge - "message received" + 204 # response without entity body end end