Skip to content

Commit

Permalink
[Fix][Web] Fix web SSE problem (#2191)
Browse files Browse the repository at this point in the history
* feat: use-service hooks

* feat: SSE express代理

* Update MonitorController.java

---------

Co-authored-by: zhu-mingye <[email protected]>
  • Loading branch information
yqwoe and Zzm0809 authored Aug 10, 2023
1 parent a08b334 commit dabb4d8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.util.concurrent.TimeUnit;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down Expand Up @@ -66,7 +65,6 @@ public Result<List<MetricsVO>> getData(@RequestParam Long startTime, Long endTim
}

@GetMapping(value = "/getLastUpdateData", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
@CrossOrigin("*")
@PublicInterface
@ApiOperation("Get Last Update Data")
public SseEmitter getLastUpdateData(Long lastTime) {
Expand Down
12 changes: 11 additions & 1 deletion dinky-web/config/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,19 @@ export default {
// target: 'https://preview.pro.ant.design',
// 配置了这个可以从 http 代理到 https
// 依赖 origin 的功能可能需要这个,比如 cookie
secure: false,
changeOrigin: true,
logLevel: 'debug',
pathRewrite: { '^': '' },
}
onProxyRes: (proxyRes, req, res) => {
res.header({
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache, no-transform',
Connection: 'keep-alive',
'X-Accel-Buffering': 'noe',
});
},
},
},

/**
Expand Down
7 changes: 1 addition & 6 deletions dinky-web/src/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,7 @@ export async function removeData(url: string, params: [any]) {
});
}
export function getSseData(url: string) {
const {REACT_APP_ENV = 'dev'} = process.env;

// @ts-ignore
const address = proxy[REACT_APP_ENV]["/api/"].target || ""

return new EventSource(address + url);
return new EventSource(url);
}


Expand Down

0 comments on commit dabb4d8

Please sign in to comment.