ReviewOS

also looking at this

stacks/rpx

feat: imgx integration — on-the-fly image transforms from query params

#2264
Merged glennmichael123 wants to merge feat/imgx-integration into main
15 files +1118 -16
packages/rpx/src/start.tsmodified+17-4
Changes to packages/rpx/src/start.ts
@@ -1,5 +1,5 @@
11/* eslint-disable no-console */
2import type { BaseProxyConfig, CleanupOptions, LoadBalancerConfig, ProxyConfig, ProxyFrom, ProxyOption, ProxyOptions, ProxySetupOptions, ResolvedProxyOptions, SingleProxyConfig, SSLConfig, StartOptions } from './types'
2import type { BaseProxyConfig, CleanupOptions, ImgxOptions, LoadBalancerConfig, ProxyConfig, ProxyFrom, ProxyOption, ProxyOptions, ProxySetupOptions, ResolvedProxyOptions, SingleProxyConfig, SSLConfig, StartOptions } from './types'
33import { exec, execSync } from 'node:child_process'
44import * as fs from 'node:fs'
55import * as http from 'node:http'
@@ -15,6 +15,7 @@ import { config } from './config'
1515import { runViaDaemon } from './daemon-runner'
1616import { addHosts, checkHosts, removeHosts } from './hosts'
1717import { checkExistingCertificates, cleanupCertificates, generateCertificate, httpsConfig, loadSSLConfig } from './https'
18import { resolveImgx } from './imgx'
1819import { createUpstreamPool, primaryUpstreamUrl, startHealthChecks, stopHealthChecks } from './load-balancer'
1920import type { UpstreamPool } from './load-balancer'
2021import { DefaultPortManager, findAvailablePort, isPortInUse } from './port-manager'
@@ -486,6 +487,7 @@ async function createProxyServer(
486487 auth?: ResolvedAuth,
487488 originalFrom?: ProxyFrom,
488489 loadBalancer?: LoadBalancerConfig,
490 imgx?: boolean | ImgxOptions,
489491): Promise<void> {
490492 debugLog('proxy', `Creating proxy server ${from} -> ${to} with cleanUrls: ${cleanUrls}`, verbose)
491493
@@ -511,6 +513,7 @@ async function createProxyServer(
511513 upstreamPool: pool,
512514 cleanUrls: cleanUrls || false,
513515 changeOrigin: changeOrigin || false,
516 imgx: resolveImgx(imgx),
514517 basePath: '/',
515518 auth,
516519 } as ProxyRoute,
@@ -630,7 +633,7 @@ export async function setupProxy(options: ProxySetupOptions): Promise<void> {
630633 debugLog('setup', `Using standard ${targetPort === 443 ? 'HTTPS' : 'HTTP'} port ${targetPort} for ${to}`, verbose)
631634 }
632635
633 await createProxyServer(from, to, finalPort, sourceUrl, ssl, vitePluginUsage, verbose, cleanUrls, changeOrigin, resolveAuth((options as { auth?: import('./types').BasicAuthConfig }).auth), originalFrom, options.loadBalancer)
636 await createProxyServer(from, to, finalPort, sourceUrl, ssl, vitePluginUsage, verbose, cleanUrls, changeOrigin, resolveAuth((options as { auth?: import('./types').BasicAuthConfig }).auth), originalFrom, options.loadBalancer, options.imgx)
634637 }
635638 catch (err) {
636639 debugLog('setup', `Setup failed: ${err}`, verbose)
@@ -735,6 +738,7 @@ export function startProxy(options: ProxyOption): void {
735738 path: mergedOptions.path,
736739 cleanUrls: mergedOptions.cleanUrls,
737740 changeOrigin: mergedOptions.changeOrigin,
741 imgx: mergedOptions.imgx,
738742 pathRewrites: mergedOptions.pathRewrites,
739743 }],
740744 verbose: mergedOptions.verbose,
@@ -796,6 +800,7 @@ export function startProxy(options: ProxyOption): void {
796800 cleanup: mergedOptions.cleanup,
797801 vitePluginUsage: mergedOptions.vitePluginUsage,
798802 changeOrigin: mergedOptions.changeOrigin,
803 imgx: mergedOptions.imgx,
799804 verbose: mergedOptions.verbose,
800805 regenerateUntrustedCerts: mergedOptions.regenerateUntrustedCerts,
801806 }
@@ -855,6 +860,7 @@ export async function startProxies(options?: ProxyOptions): Promise<void> {
855860 verbose: false,
856861 cleanUrls: false,
857862 changeOrigin: false,
863 imgx: false,
858864 regenerateUntrustedCerts: true,
859865 } as ResolvedProxyOptions
860866
@@ -889,7 +895,7 @@ export async function startProxies(options?: ProxyOptions): Promise<void> {
889895 if (mergedOptions.viaDaemon) {
890896 const isMulti = 'proxies' in mergedOptions && Array.isArray(mergedOptions.proxies)
891897 const proxies = isMulti
892 ? (mergedOptions.proxies as Array<BaseProxyConfig & { cleanUrls?: boolean, changeOrigin?: boolean }>)
898 ? (mergedOptions.proxies as Array<BaseProxyConfig & { cleanUrls?: boolean, changeOrigin?: boolean, imgx?: boolean | ImgxOptions }>)
893899 .map(p => ({
894900 id: p.id,
895901 from: p.from,
@@ -897,6 +903,7 @@ export async function startProxies(options?: ProxyOptions): Promise<void> {
897903 path: p.path,
898904 cleanUrls: p.cleanUrls ?? mergedOptions.cleanUrls,
899905 changeOrigin: p.changeOrigin ?? mergedOptions.changeOrigin,
906 imgx: p.imgx ?? mergedOptions.imgx,
900907 pathRewrites: p.pathRewrites,
901908 }))
902909 : [{
@@ -906,6 +913,7 @@ export async function startProxies(options?: ProxyOptions): Promise<void> {
906913 path: mergedOptions.path,
907914 cleanUrls: mergedOptions.cleanUrls,
908915 changeOrigin: mergedOptions.changeOrigin,
916 imgx: mergedOptions.imgx,
909917 pathRewrites: mergedOptions.pathRewrites,
910918 }]
911919 await runViaDaemon({ proxies, verbose })
@@ -1080,6 +1088,7 @@ export async function startProxies(options?: ProxyOptions): Promise<void> {
10801088 cleanUrls: proxy.cleanUrls ?? ('cleanUrls' in mergedOptions ? mergedOptions.cleanUrls : false),
10811089 vitePluginUsage: mergedOptions.vitePluginUsage,
10821090 changeOrigin: proxy.changeOrigin ?? mergedOptions.changeOrigin,
1091 imgx: proxy.imgx ?? mergedOptions.imgx,
10831092 verbose,
10841093 _cachedSSLConfig: mergedOptions._cachedSSLConfig,
10851094 } as ProxyOption))
@@ -1092,6 +1101,7 @@ export async function startProxies(options?: ProxyOptions): Promise<void> {
10921101 vitePluginUsage: mergedOptions.vitePluginUsage,
10931102 start: ('start' in mergedOptions) ? mergedOptions.start : undefined,
10941103 changeOrigin: mergedOptions.changeOrigin,
1104 imgx: mergedOptions.imgx,
10951105 auth: 'auth' in mergedOptions ? mergedOptions.auth : undefined,
10961106 verbose,
10971107 _cachedSSLConfig: mergedOptions._cachedSSLConfig,
@@ -1355,6 +1365,7 @@ export async function startProxies(options?: ProxyOptions): Promise<void> {
13551365 verbose: option.verbose || false,
13561366 _cachedSSLConfig: mergedOptions._cachedSSLConfig,
13571367 changeOrigin: option.changeOrigin || false,
1368 imgx: option.imgx,
13581369 loadBalancer: option.loadBalancer,
13591370 auth: option.auth,
13601371 path: option.path,
@@ -1397,6 +1408,7 @@ export async function collectRouteEntries(
13971408 const basePath = normalizePathPrefix(routePath)
13981409
13991410 const auth = resolveAuth(option.auth)
1411 const imgx = resolveImgx(option.imgx)
14001412
14011413 // Redirect route: answer with a Location (e.g. an alternate domain → its
14021414 // canonical host). Takes precedence over proxy/static — no upstream needed.
@@ -1414,7 +1426,7 @@ export async function collectRouteEntries(
14141426 routeEntries.push({
14151427 host: domain,
14161428 path: routePath,
1417 route: { static: resolveStaticRoute(option.static, cleanUrls), cleanUrls, basePath, auth },
1429 route: { static: resolveStaticRoute(option.static, cleanUrls), cleanUrls, imgx, basePath, auth },
14181430 })
14191431 debugLog('proxies', `Route: ${domain}${routePath ?? ''} → static ${typeof option.static === 'string' ? option.static : option.static.dir}${auth ? ' (auth)' : ''}`, verbose)
14201432 }
@@ -1435,6 +1447,7 @@ export async function collectRouteEntries(
14351447 upstreamPool: pool,
14361448 cleanUrls,
14371449 changeOrigin: option.changeOrigin || false,
1450 imgx,
14381451 pathRewrites: option.pathRewrites,
14391452 basePath,
14401453 auth,