Skip to content

Proxy, HTTPS, and full test coverage#33

Merged
pillsilly merged 9 commits into
masterfrom
proxy
May 18, 2026
Merged

Proxy, HTTPS, and full test coverage#33
pillsilly merged 9 commits into
masterfrom
proxy

Conversation

@pillsilly
Copy link
Copy Markdown
Owner

@pillsilly pillsilly commented May 14, 2026

Summary

  • New PROXY_STATIC_FILE_WISE mode — serve static files first, proxy all other requests to --proxyTarget. Supports WebSocket upgrade (for HMR/dev servers), strips proxy-fingerprint headers (x-forwarded-*, via), rewrites origin/referer to match the target, and auto-rewrites upstream redirect Location headers to the proxy origin.
  • HTTPS support--https, --httpsKey, --httpsCert CLI flags. Falls back to bundled server.key/server.cert when no custom path given. HTTPS server shares the same routing as HTTP.
  • New CLI flags: --proxyStaticFileWise, --https, --httpsKey, --httpsCert
  • Refactored run.ts — split monolithic run() into createLegacyServer, createProxyStaticFirstServer, createHttpOrHttpsServer, normalizeProxyRequest, rewriteReferer, resolveHttpsPath, parsePort, validateArguments. Uses http-proxy-middleware v3 API directly (was lazy-required before).
  • TypeScript fixes — widen mode literal type to Mode union, drop removed logLevel option, cast Duplex to net.Socket for proxy upgrade.
  • Refactored bin.ts — extracted main() and runIfMain() for clean error handling and testability. run errors now log to stderr and exit with code 1 instead of crashing.
  • Fixed src/run-https.ts — use path.resolve(__dirname, ...) for cert/key paths so the binary can find them when packaged.
  • 100% test coverage — 27 tests (up from 14), covering SPA mode, proxy-static-first with WebSocket, HTTPS, header normalization, redirect rewriting, argument validation, error paths, and uncaughtException handling.

Files changed

File Δ
src/run.ts +279/-61
test/test.spec.ts +668/-78
README.md +221/-61
test/bin.spec.ts +150/-8
src/bin.ts +43/-15
src/run-https.ts +4/-2
package.json +3/-1

Test plan

  • npm test — 27 tests pass, 100% branch/function/line/statement coverage
  • npx tsc -p tsconfig.json --emitDeclarationOnly — zero errors

@pillsilly pillsilly changed the title complex_proxy Proxy, HTTPS, and full test coverage May 14, 2026
pillsilly added 6 commits May 15, 2026 14:03
babel.config.js unused — build uses tsup (esbuild), test uses esbuild-jest.
.eslintrc.js unused — ESLint v9 uses eslint.config.js (flat config).
test.mjs unused — leftover scratch file.
Remove orphaned @babel/preset-env and @babel/preset-typescript devDependencies.
@pillsilly pillsilly merged commit 98640de into master May 18, 2026
@pillsilly pillsilly deleted the proxy branch May 18, 2026 06:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant