Supra_App/src/routes/api/scrcpy-server/+server.ts
pakintada@gmail.com 1156b5e6c3 feat: scrcpy
- add: scrcpy for previewing android screen.
- change: notification of android connection fail to dialog.
- wip: firmware packing (on file listing issue)
- add: reject button on announcement dialog with callback.

Signed-off-by: pakintada@gmail.com <Pakin>
2026-07-16 14:52:54 +07:00

38 lines
1.2 KiB
TypeScript

/**
* GET /api/scrcpy-server
*
* Proxies the scrcpy-server binary from GitHub releases.
* Fixes CORS issues (GitHub doesn't send Access-Control-Allow-Origin for binaries).
* Server-side fetch has no CORS restrictions.
*
* Response is cached by the browser for 24 hours via Cache-Control header.
*/
import type { RequestHandler } from './$types';
const GITHUB_URL =
'https://github.com/Genymobile/scrcpy/releases/download/v2.3/scrcpy-server-v2.3';
export const GET: RequestHandler = async () => {
try {
const response = await fetch(GITHUB_URL);
if (!response.ok) {
console.error(`[scrcpy-server] GitHub returned ${response.status}`);
return new Response(`Failed to fetch scrcpy-server: ${response.status}`, {
status: 502
});
}
// Stream the response directly — don't buffer the entire binary in memory on the server
return new Response(response.body, {
headers: {
'Content-Type': 'application/octet-stream',
'Cache-Control': 'public, max-age=86400, immutable'
}
});
} catch (e) {
console.error('[scrcpy-server] Fetch failed:', e);
return new Response('Failed to fetch scrcpy-server from GitHub', { status: 500 });
}
};