@domain.js/main 0.5.3 → 0.6.0

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.
@@ -33,6 +33,8 @@ export interface Profile {
33
33
  isSocket?: boolean;
34
34
  /** socket 的时候加入的房间 */
35
35
  roomId?: string;
36
+ /** 是否需要返回 stream */
37
+ needStream?: boolean;
36
38
  }
37
39
  export interface HttpCodes {
38
40
  [propName: string]: number;
@@ -90,6 +90,16 @@ function Router(deps) {
90
90
  if (!method || !lodash_1.default.isFunction(method)) {
91
91
  throw Error(`Missing domain method: ${methodPath}`);
92
92
  }
93
+ const send = (res, results, isEventStream = false) => {
94
+ if ("pipe" in results) {
95
+ if (isEventStream)
96
+ res.setHeader("Content-Type", "text/event-stream");
97
+ results.pipe(res);
98
+ }
99
+ else {
100
+ res.send(code, results);
101
+ }
102
+ };
93
103
  server[verb](route, async (req, res, next) => {
94
104
  const profile = makeProfile(req, methodPath, makeProfileHook);
95
105
  if (resource)
@@ -129,7 +139,7 @@ function Router(deps) {
129
139
  }
130
140
  }
131
141
  else {
132
- res.send(code, code !== 204 && results);
142
+ send(res, code !== 204 && results, req.header("response-event-stream") === "yes");
133
143
  }
134
144
  }
135
145
  catch (e) {
@@ -74,6 +74,7 @@ function Utils(cnf) {
74
74
  requestId: req.id(),
75
75
  method,
76
76
  type: "user",
77
+ needStream: req.headers["response-event-stream"] === "yes",
77
78
  extra: {},
78
79
  };
79
80
  if (req.headers["x-auth-user-type"]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domain.js/main",
3
- "version": "0.5.3",
3
+ "version": "0.6.0",
4
4
  "description": "DDD framework",
5
5
  "main": "dist/index.js",
6
6
  "bin": {