@blocklet/uploader-server 0.1.68 → 0.1.70

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.
@@ -107,7 +107,7 @@ export const initStaticResourceMiddleware = ({
107
107
  ...options
108
108
  })(req, res, next);
109
109
  } else {
110
- res.status(404).end();
110
+ next();
111
111
  }
112
112
  };
113
113
  };
@@ -120,18 +120,27 @@ export const initProxyToMediaKitUploadsMiddleware = ({ options, express } = {})
120
120
  const filename = basename(req.url);
121
121
  req.url = joinUrl("/uploads/", filename);
122
122
  setPDFDownloadHeader(req, res);
123
+ proxy.once("proxyRes", (proxyRes, req2, res2) => {
124
+ if (proxyRes.statusCode >= 200 && proxyRes.statusCode < 300) {
125
+ res2.writeHead(proxyRes.statusCode, proxyRes.headers);
126
+ proxyRes.pipe(res2);
127
+ } else {
128
+ next();
129
+ }
130
+ });
131
+ proxy.once("error", (err, req2, res2) => {
132
+ next(err);
133
+ });
123
134
  proxy.web(
124
135
  req,
125
136
  res,
126
137
  {
127
138
  target: mediaKitInfo.webEndpoint,
128
139
  changeOrigin: true,
140
+ selfHandleResponse: true,
129
141
  ...options
130
142
  },
131
- (err) => {
132
- console.error("Proxy error:", err);
133
- next();
134
- }
143
+ next
135
144
  );
136
145
  };
137
146
  };
@@ -127,7 +127,7 @@ const initStaticResourceMiddleware = ({
127
127
  ...options
128
128
  })(req, res, next);
129
129
  } else {
130
- res.status(404).end();
130
+ next();
131
131
  }
132
132
  };
133
133
  };
@@ -145,14 +145,23 @@ const initProxyToMediaKitUploadsMiddleware = ({
145
145
  const filename = basename(req.url);
146
146
  req.url = joinUrl("/uploads/", filename);
147
147
  setPDFDownloadHeader(req, res);
148
+ proxy.once("proxyRes", (proxyRes, req2, res2) => {
149
+ if (proxyRes.statusCode >= 200 && proxyRes.statusCode < 300) {
150
+ res2.writeHead(proxyRes.statusCode, proxyRes.headers);
151
+ proxyRes.pipe(res2);
152
+ } else {
153
+ next();
154
+ }
155
+ });
156
+ proxy.once("error", (err, req2, res2) => {
157
+ next(err);
158
+ });
148
159
  proxy.web(req, res, {
149
160
  target: mediaKitInfo.webEndpoint,
150
161
  changeOrigin: true,
162
+ selfHandleResponse: true,
151
163
  ...options
152
- }, err => {
153
- console.error("Proxy error:", err);
154
- next();
155
- });
164
+ }, next);
156
165
  };
157
166
  };
158
167
  exports.initProxyToMediaKitUploadsMiddleware = initProxyToMediaKitUploadsMiddleware;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/uploader-server",
3
- "version": "0.1.68",
3
+ "version": "0.1.70",
4
4
  "description": "blocklet upload server",
5
5
  "publishConfig": {
6
6
  "access": "public"