我有一個使用 EventStream 的 ReactJS 客戶端和一個實現(xiàn) SSE 的 golang 后端。當我將瀏覽器連接到在 localhost 上運行的后端時,以及當我的后端在帶有端口轉發(fā)的 k8s 上運行時,一切似乎都正常。一旦我使用主機名創(chuàng)建入口(這樣我就不必一直進行端口轉發(fā)),SSE 就停止工作。我仍然看到客戶端發(fā)送請求,并且該請求被后端接收并注冊。但是,當發(fā)送事件時,它永遠不會到達我的 ReactJS 應用程序。在我的 ReactJS 應用程序中:export default class CustomersTable extends Component { constructor(props) { super(props) this.eventSource = new EventSource('/v1/events') } updateCustomerState(e) { let event = JSON.parse(e.data) switch (event.event_type) { case 'customerStateUpdate': let newData = this.state.customers.map(item => { if (item.name === event.customer_name) { item.k8sState = event.customer_state } return item }) this.setState(Object.assign({}, { customers: newData })) break case 'contentUpdate': this.reload() break default: break } } componentDidMount() { this.setState({ isLoading: true }) ReactModal.setAppElement('body') this.reload() this.eventSource.onmessage = e => this.updateCustomerState(e) } componentWillUnmount() { this.eventSource.close() }...
1 回答

慕標5832272
TA貢獻1966條經(jīng)驗 獲得超4個贊
我在 Nginx Ingress 上使用了我的 SSE 應用程序:
annotations: nginx.ingress.kubernetes.io/proxy-read-timeout: "21600" nginx.ingress.kubernetes.io/eventsource: "true"
- 1 回答
- 0 關注
- 360 瀏覽
添加回答
舉報
0/150
提交
取消