@rip-lang/server 1.1.9 → 1.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/server.rip +11 -2
package/package.json
CHANGED
package/server.rip
CHANGED
|
@@ -817,11 +817,14 @@ class Server
|
|
|
817
817
|
|
|
818
818
|
return @status() if url.pathname is '/status'
|
|
819
819
|
|
|
820
|
-
# SSE hot-reload: intercept /{prefix}/watch
|
|
820
|
+
# SSE hot-reload: intercept /{prefix}/watch
|
|
821
821
|
path = url.pathname
|
|
822
822
|
if path.endsWith('/watch')
|
|
823
823
|
watchPrefix = path.slice(0, -6) # strip '/watch'
|
|
824
|
-
|
|
824
|
+
if @watchGroups.has(watchPrefix)
|
|
825
|
+
return @handleWatch(watchPrefix)
|
|
826
|
+
else
|
|
827
|
+
return new Response('', { status: 503, headers: { 'Retry-After': '2' } })
|
|
825
828
|
|
|
826
829
|
if url.pathname is '/server'
|
|
827
830
|
headers = new Headers({ 'content-type': 'text/plain' })
|
|
@@ -875,15 +878,21 @@ class Server
|
|
|
875
878
|
return new Response('not-found', { status: 404 }) unless group
|
|
876
879
|
encoder = new TextEncoder()
|
|
877
880
|
client = null
|
|
881
|
+
heartbeat = null
|
|
878
882
|
new Response new ReadableStream(
|
|
879
883
|
start: (controller) ->
|
|
880
884
|
send = (event) ->
|
|
881
885
|
try controller.enqueue encoder.encode("event: #{event}\n\n")
|
|
882
886
|
catch then null
|
|
887
|
+
ping = ->
|
|
888
|
+
try controller.enqueue encoder.encode(":\n\n")
|
|
889
|
+
catch then null
|
|
883
890
|
client = { send }
|
|
884
891
|
group.sseClients.add(client)
|
|
892
|
+
heartbeat = setInterval ping, 5000
|
|
885
893
|
send('connected')
|
|
886
894
|
cancel: ->
|
|
895
|
+
clearInterval(heartbeat) if heartbeat
|
|
887
896
|
group.sseClients.delete(client) if client
|
|
888
897
|
),
|
|
889
898
|
headers:
|