upload zip archive from strava

This commit is contained in:
Davide Scaini
2026-04-10 22:26:11 +02:00
parent fc6c00c6eb
commit da622131fd
4 changed files with 77 additions and 1 deletions
+21
View File
@@ -25,6 +25,27 @@ export default defineConfig({
// In production nginx handles this — same pattern, no code change needed.
server: {
proxy: {
// SSE response to a POST — Vite's default proxy buffers the full body before
// forwarding, which breaks streaming and can cause EPIPE on long uploads.
// selfHandleResponse + manual pipe sends chunks as they arrive.
'/api/upload/strava-zip': {
target: serveTarget,
changeOrigin: true,
selfHandleResponse: true,
configure: (proxy) => {
proxy.on('proxyRes', (proxyRes, req, res) => {
res.writeHead(proxyRes.statusCode ?? 200, proxyRes.headers);
proxyRes.pipe(res, { end: true });
});
proxy.on('error', (err, _req, res) => {
if (err.code === 'EPIPE' || err.code === 'ECONNRESET') return;
if (!res.headersSent) {
res.writeHead(502);
res.end('proxy error');
}
});
},
},
'/api': {
target: serveTarget,
changeOrigin: true,
+11
View File
@@ -732,6 +732,17 @@ try {
}
};
xhr.onload = () => {
// Fires when the request completes. If we already got a 'done' or 'error'
// SSE event via onprogress the status is already set. If not (e.g. a non-SSE
// error response), surface the failure.
if (xhr.status !== 200) {
zipStatus.textContent = `Upload failed (${xhr.status}).`;
zipStatus.style.color = '#f87171';
zipInput.value = '';
}
};
xhr.onerror = () => {
zipStatus.textContent = 'Upload failed — check your connection.';
zipStatus.style.color = '#f87171';