Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivanwangcy committed Aug 15, 2024
1 parent ccbf94b commit 11a84ab
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions node/server/httpSSE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# SSE 服务设计

使用 EventSource 请求 SSE 接口

```sh
npm install @microsoft/fetch-event-source
```

get & post 方式请求

```js
// BEFORE:
const sse = new EventSource('/api/sse');
sse.onmessage = (ev) => {
console.log(ev.data);
};

// AFTER:
import { fetchEventSource } from '@microsoft/fetch-event-source';

await fetchEventSource('/api/sse', {
onmessage(ev) {
console.log(ev.data);
}
});
```

## 基于 express sse 服务

Expand All @@ -11,3 +35,4 @@ express-sse: <https://www.npmjs.com/package/express-sse?ref=ghost.ably.com>

express-sse github: <https://github.com/dpskvn/express-sse>


0 comments on commit 11a84ab

Please sign in to comment.