Small iOS-only Nitro wrapper around GCDWebServer for a local reverse proxy or a single-file download.
import { createGCDWebServer } from 'react-native-gcd-webserver';
const server = createGCDWebServer();
const path = '/a-random-session-token';
const started = server.startFileServer(fileUri, path, {
bindToLocalhost: false,
});
if (!started) throw new Error('Could not start the download server');
const downloadURL = `${server.getServerURL().replace(/\/$/, '')}${path}`;
// Stop when the download screen closes, then release your temporary file.
server.stop();startFileServer(fileUri, path, options?) serves only a readable regular file at the supplied absolute URL path. It supports GET, HEAD, and byte ranges, and sends Content-Disposition: attachment and Cache-Control: no-store. It does not expose a directory, accept uploads, forward requests, or delete the caller's file. Other paths and methods receive 404. Invalid local file URIs, paths, or ports throw; a bind/start failure returns false.
The path uses unescaped ASCII letters, digits, ., _, ~, -, and /, excludes empty or traversal segments, and is case-sensitive. Use a fresh unpredictable token for each session, show its URL only to the user, and keep the file available until the server stops. File URIs such as file:///.../My%20Backup.lifejournal are decoded correctly; remote URLs, directory paths, and final symbolic links are rejected.
File-mode defaults are port: 0 (choose a free port), bindToLocalhost: true, and automaticallySuspendInBackground: true. For Wi-Fi access use bindToLocalhost: false, configure a real local-network permission description in the app, and keep the app foregrounded. The connection uses HTTP on the local network. Do not enable port mapping or expose sensitive files publicly.
createGCDWebServer() creates an independent server instance. The existing GCDWebServer singleton and update-proxy helpers keep their previous defaults and behavior. Starting either mode replaces the handlers of that instance; an independent download instance does not alter the update proxy.