@blocklet/uploader-server 0.1.69 → 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.
|
@@ -120,12 +120,24 @@ 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
143
|
next
|
|
@@ -145,9 +145,21 @@ 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
164
|
}, next);
|
|
153
165
|
};
|