diff --git a/.github/renovate.json b/.github/renovate.json index 3a9d450..66937d2 100644 --- a/.github/renovate.json +++ b/.github/renovate.json @@ -1,5 +1,3 @@ { - "extends": [ - "@ow3" - ] + "extends": ["@ow3"] } diff --git a/.vscode/settings.json b/.vscode/settings.json index 412521b..9b1f20e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -68,12 +68,8 @@ "yaml", "toml" ], - "cSpell.ignorePaths": [ - "node_modules" - ], - "cSpell.dictionaries": [ - "custom-dictionary" - ], + "cSpell.ignorePaths": ["node_modules"], + "cSpell.dictionaries": ["custom-dictionary"], "cSpell.diagnosticLevel": "Hint", "cSpell.customDictionaries": { "bun-plugin-env": { diff --git a/bin/cli.ts b/bin/cli.ts index 49f4a71..4080fad 100644 --- a/bin/cli.ts +++ b/bin/cli.ts @@ -1,10 +1,10 @@ import os from 'node:os' +import { log } from '@stacksjs/logging' import { CAC } from 'cac' import { readFileSync, writeFileSync } from 'fs-extra' -import { log } from '@stacksjs/logging' -import { startProxy } from '../src/start' -import { config } from '../src/config' import { version } from '../package.json' +import { config } from '../src/config' +import { startProxy } from '../src/start' const cli = new CAC('reverse-proxy') @@ -26,7 +26,9 @@ cli .example('reverse-proxy start --from localhost:3000 --to my-project.localhost') .example('reverse-proxy start --from localhost:3001 --to my-project.localhost/api') .example('reverse-proxy start --from localhost:3000 --to localhost:3001') - .example('reverse-proxy start --from localhost:3000 --to my-project.test --keyPath /absolute/path/to/key --certPath /absolute/path/to/cert') + .example( + 'reverse-proxy start --from localhost:3000 --to my-project.test --keyPath /absolute/path/to/key --certPath /absolute/path/to/cert', + ) .action(async (options?: Options) => { if (options?.from || options?.to) { startProxy({ @@ -49,27 +51,29 @@ cli certPath: options?.certPath, }) } - } - else { + } else { // eslint-disable-next-line no-console console.log('No proxies found in the config') } }) cli - .command('update:etc-hosts', 'Update the /etc/hosts file with the proxy domains. Please note, this command requires sudo/admin permissions.') + .command( + 'update:etc-hosts', + 'Update the /etc/hosts file with the proxy domains. Please note, this command requires sudo/admin permissions.', + ) .alias('update-etc-hosts') .example('sudo reverse-proxy update:etc-hosts') .example('sudo reverse-proxy update-etc-hosts') .action(async () => { log.info('Ensuring /etc/hosts file covers the proxy domain/s...') - const hostsFilePath = os.platform() === 'win32' - ? 'C:\\Windows\\System32\\drivers\\etc\\hosts' - : '/etc/hosts' + const hostsFilePath = os.platform() === 'win32' ? 'C:\\Windows\\System32\\drivers\\etc\\hosts' : '/etc/hosts' if (config && typeof config === 'object') { - const entriesToAdd = Object.entries(config).map(([from, to]) => `127.0.0.1 ${to} # reverse-proxy mapping for ${from}`) + const entriesToAdd = Object.entries(config).map( + ([from, to]) => `127.0.0.1 ${to} # reverse-proxy mapping for ${from}`, + ) // Ensure "127.0.0.1 localhost" is in the array entriesToAdd.push('127.0.0.1 localhost # essential localhost mapping') @@ -86,8 +90,7 @@ cli // If not, append it currentHostsContent += `\n${entry}` updated = true - } - else { + } else { log.info(`Entry for ${host} already exists in the hosts file.`) } } @@ -95,30 +98,24 @@ cli if (updated) { writeFileSync(hostsFilePath, currentHostsContent, 'utf8') log.success('Hosts file updated with latest proxy domains.') - } - else { + } else { log.info('No new entries were added to the hosts file.') } - } - catch (error: unknown) { + } catch (error: unknown) { if ((error as NodeJS.ErrnoException).code === 'EACCES') console.error('Permission denied. Please run this command with administrative privileges.') - else - console.error(`An error occurred: ${(error as NodeJS.ErrnoException).message}`) + else console.error(`An error occurred: ${(error as NodeJS.ErrnoException).message}`) } - } - else { + } else { // eslint-disable-next-line no-console console.log('No proxies found. Is your config configured properly?') } }) -cli - .command('version', 'Show the version of the Reverse Proxy CLI') - .action(() => { - // eslint-disable-next-line no-console - console.log(version) - }) +cli.command('version', 'Show the version of the Reverse Proxy CLI').action(() => { + // eslint-disable-next-line no-console + console.log(version) +}) cli.version(version) cli.help() diff --git a/biome.json b/biome.json index 207499b..3fce764 100644 --- a/biome.json +++ b/biome.json @@ -5,9 +5,7 @@ }, "overrides": [ { - "include": [ - ".vscode/**" - ], + "include": [".vscode/**"], "json": { "parser": { "allowComments": true, diff --git a/bun.lockb b/bun.lockb index e2d6708..18f971c 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/commitlint.config.js b/commitlint.config.js index aaa7b8e..56e966c 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -6,7 +6,7 @@ const config = { }, prompt: { messages: { - type: 'Select the type of change that you\'re committing:', + type: "Select the type of change that you're committing:", scope: 'Select the SCOPE of this change (optional):', customScope: 'Select the SCOPE of this change:', subject: 'Write a SHORT, IMPERATIVE tense description of the change:\n', @@ -22,12 +22,24 @@ const config = { { value: 'fix', name: 'fix: 🐛 A bug fix', emoji: ':bug:' }, { value: 'docs', name: 'docs: 📝 Documentation only changes', emoji: ':memo:' }, { value: 'style', name: 'style: 💄 Changes that do not affect the meaning of the code', emoji: ':lipstick:' }, - { value: 'refactor', name: 'refactor: ♻️ A code change that neither fixes a bug nor adds a feature', emoji: ':recycle:' }, + { + value: 'refactor', + name: 'refactor: ♻️ A code change that neither fixes a bug nor adds a feature', + emoji: ':recycle:', + }, { value: 'perf', name: 'perf: ⚡️ A code change that improves performance', emoji: ':zap:' }, - { value: 'test', name: 'test: ✅ Adding missing tests or adjusting existing tests', emoji: ':white_check_mark:' }, - { value: 'build', name: 'build: 📦️ Changes that affect the build system or external dependencies', emoji: ':package:' }, + { + value: 'test', + name: 'test: ✅ Adding missing tests or adjusting existing tests', + emoji: ':white_check_mark:', + }, + { + value: 'build', + name: 'build: 📦️ Changes that affect the build system or external dependencies', + emoji: ':package:', + }, { value: 'ci', name: 'ci: 🎡 Changes to our CI configuration files and scripts', emoji: ':ferris_wheel:' }, - { value: 'chore', name: 'chore: 🔨 Other changes that don\'t modify src or test files', emoji: ':hammer:' }, + { value: 'chore', name: "chore: 🔨 Other changes that don't modify src or test files", emoji: ':hammer:' }, { value: 'revert', name: 'revert: ⏪️ Reverts a previous commit', emoji: ':rewind:' }, ], useEmoji: false, diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index 5788a9f..5047942 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -21,8 +21,6 @@ export default defineConfig({ }, ], - socialLinks: [ - { icon: 'github', link: 'https://github.com/vuejs/vitepress' }, - ], + socialLinks: [{ icon: 'github', link: 'https://github.com/vuejs/vitepress' }], }, }) diff --git a/package.json b/package.json index c1e7bd2..7c56be1 100644 --- a/package.json +++ b/package.json @@ -40,11 +40,7 @@ "bun-reverse-proxy": "./dist/cli.js", "reverse-proxy": "./dist/cli.js" }, - "files": [ - "dist", - "scripts", - "src" - ], + "files": ["dist", "scripts", "src"], "scripts": { "build": "bun scripts/build.ts && bun run compile", "compile": "bun build ./bin/cli.ts --compile --external rollup --minify --sourcemap --outfile dist/reverse-proxy", diff --git a/scripts/build.ts b/scripts/build.ts index b37bdc3..8f8a3a4 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -1,7 +1,7 @@ import path from 'node:path' +import { log } from '@stacksjs/logging' import { $ } from 'bun' import dts from 'bun-plugin-dts-auto' -import { log } from '@stacksjs/logging' log.info('Building...') diff --git a/src/start.ts b/src/start.ts index 85ca13d..3f1905c 100644 --- a/src/start.ts +++ b/src/start.ts @@ -1,6 +1,6 @@ -import * as net from 'node:net' import * as http from 'node:http' import * as https from 'node:https' +import * as net from 'node:net' import { bold, dim, green, log } from '@stacksjs/cli' import { version } from '../package.json' @@ -18,7 +18,9 @@ export async function startServer(option: Option = { from: 'localhost:3000', to: log.debug('Starting Reverse Proxy Server') // Parse the option.from URL to dynamically set hostname and port - const fromUrl = new URL(option.from ? (option.from.startsWith('http') ? option.from : `http://${option.from}`) : 'http://localhost:3000') + const fromUrl = new URL( + option.from ? (option.from.startsWith('http') ? option.from : `http://${option.from}`) : 'http://localhost:3000', + ) const hostname = fromUrl.hostname const port = Number.parseInt(fromUrl.port) || (fromUrl.protocol === 'https:' ? 443 : 80) @@ -27,8 +29,10 @@ export async function startServer(option: Option = { from: 'localhost:3000', to: log.debug(`Successfully connected to ${option.from}`) socket.end() - const cert = '-----BEGIN CERTIFICATE-----\r\nMIIDBjCCAe6gAwIBAgIUAdYO7vc82qKcT2DJn7WXylTNN6kwDQYJKoZIhvcNAQEF\r\nBQAwLTELMAkGA1UEBhMCQVUxEzARBgNVBAgTClNvbWUtU3RhdGUxCTAHBgNVBAoT\r\nADAeFw0yNDAzMDkxNzUwMjZaFw0yNDAzMTAxNzUwMjZaMC0xCzAJBgNVBAYTAkFV\r\nMRMwEQYDVQQIEwpTb21lLVN0YXRlMQkwBwYDVQQKEwAwggEiMA0GCSqGSIb3DQEB\r\nAQUAA4IBDwAwggEKAoIBAQC0Nl+n9xusat7FvFn/7/NEXDn35I/T0cAiwesBbDDo\r\neXtM/iOfvTRqYS+1Kca9byC4kFuFW7cO8gsihHb2bV6YjgLkuDGYsJBfgiGVyytu\r\n+Qjm2pnsvExffWR7Z1E4v6XUm5q1p5u733jjW2Cr2Px3fzHQ3TWuAml6SyN53E57\r\nwieY1Thw2QrhG8rUxTTc140FRxaWwEMbQy5tLZXIuNy0HrcVUbmM7172ZCep997+\r\nBx+Pd7toDIuiXqS6x98Ilqv2Pa8496cnNv+jAq383bcKSCjcpRizUHH2TK7SHcNu\r\ngevBIcNuK1nZvyEgrouvG1iQUBgkV3HDGKpF3eR8JuZVAgMBAAGjHjAcMBoGA1Ud\r\nEQQTMBGGCWxvY2FsaG9zdIcEfwAAATANBgkqhkiG9w0BAQUFAAOCAQEAk0CEKSL4\r\n5TR4Z3W4yoZlHDl2ddS/uqBT6Y0hOgWqN4W9P5xow9qSZpFPr2sky7nl2xP0QR84\r\ns6oOc4/WB4RrzTxBK0ktCWok6a4apMpkdUQeYWb1eevWVSYfTp+8W8/zCJ5xW89P\r\n4nTBc9mn8wYSg4I9d2w/sGilpPNj+iahHZ4/nSpZAHN1mhz6+9LfyQuwDlMni5rG\r\nl8R/cebuzNydu5qnpwg/bS1HBzbcclM32dANGFGX0NZEs7JKh5An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DTEAlARJ6VWyrZKqsS3VxNb/QM27uF0PpL6Pp\r\nbB1mIi411hBSNHcJMr4dZQKBgD2PqV3i/SF1E/J7d53vR5HwrumxE+Ol0SZiurBc\r\n7h7yeqP4KH7L1pKvXEc4WnONlTJxKnGVBsjtbmpFBZhbkfSjV/znJ3NwTrvr8EqR\r\n0KwGuaO9INYrLxj5quu84If/vmaCAH+hjd75aDobbrnWSTTWHyXS7Z3SOSwe7VzH\r\nPpgBAoGAJbGOBQHrnFBJ79n4Q6YDzZw8LmUOxffNSO5R9N94pwLsYYe3my63VCiJ\r\n1ZTusaiH0L8En3E8PAXHGkAb1JwjjJ89cJI7y5VC5Kh6O94J2J/bbURFtOZleQc2\r\nQgCch29UPYEv39RCMgkIao+lrmyPSqZUYK5Fy2Cd9M/SBOkc/fI=\r\n-----END RSA PRIVATE KEY-----\r\n' // Proceed with setting up the reverse proxy after successful connection setupReverseProxy({ key, cert, hostname, port, option }) @@ -40,7 +44,13 @@ export async function startServer(option: Option = { from: 'localhost:3000', to: }) } -export function setupReverseProxy({ key, cert, hostname, port, option }: { key?: string, cert?: string, hostname: string, port: number, option: Option }): void { +export function setupReverseProxy({ + key, + cert, + hostname, + port, + option, +}: { key?: string; cert?: string; hostname: string; port: number; option: Option }): void { log.debug('setupReverseProxy', { key, cert, hostname, port, option }) // This server will act as a reverse proxy @@ -56,7 +66,7 @@ export function setupReverseProxy({ key, cert, hostname, port, option }: { key?: // Create a request to the target server const proxyReq = http.request(options, (proxyRes) => { - // Set the statusCode and headers from the proxied response + // Set the statusCode and headers from the proxied response res.writeHead(proxyRes.statusCode || 500, proxyRes.headers) // Pipe the proxied response's body directly to the original response proxyRes.pipe(res, { end: true }) @@ -81,19 +91,20 @@ export function setupReverseProxy({ key, cert, hostname, port, option }: { key?: // eslint-disable-next-line no-console console.log('') // eslint-disable-next-line no-console - console.log(` ${green('➜')} ${dim(option.from!)} ${dim('➜')} https://${option.to}`) + console.log(` ${green('➜')} ${dim(option.from as string)} ${dim('➜')} https://${option.to}`) }) // http to https redirect - if (option.httpsRedirect ?? true) - startHttpRedirectServer() + if (option.httpsRedirect ?? true) startHttpRedirectServer() } export function startHttpRedirectServer(): void { - http.createServer((req, res) => { - res.writeHead(301, { Location: `https://${req.headers.host}${req.url}` }) - res.end() - }).listen(80) + http + .createServer((req, res) => { + res.writeHead(301, { Location: `https://${req.headers.host}${req.url}` }) + res.end() + }) + .listen(80) } export function startProxy(option?: Option): void { @@ -105,8 +116,7 @@ export function startProxies(options?: Options): void { options.forEach((option: Option) => { startServer(option) }) - } - else { + } else { startServer(options) } } diff --git a/tsconfig.json b/tsconfig.json index d9a0183..9cc110c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,16 +1,11 @@ { "compilerOptions": { "target": "esnext", - "lib": [ - "esnext" - ], + "lib": ["esnext"], "moduleDetection": "force", "module": "esnext", "moduleResolution": "bundler", "resolveJsonModule": true, - "types": [ - "node" - ], "allowImportingTsExtensions": true, "strict": true, "strictNullChecks": true,