Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbbreuer committed May 13, 2024
1 parent e9e0feb commit 383854c
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 74 deletions.
4 changes: 1 addition & 3 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"extends": [
"@ow3"
]
"extends": ["@ow3"]
}
8 changes: 2 additions & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
51 changes: 24 additions & 27 deletions bin/cli.ts
Original file line number Diff line number Diff line change
@@ -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')

Expand All @@ -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({
Expand All @@ -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')

Expand All @@ -86,39 +90,32 @@ cli
// If not, append it
currentHostsContent += `\n${entry}`
updated = true
}
else {
} else {
log.info(`Entry for ${host} already exists in the hosts file.`)
}
}

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()
Expand Down
4 changes: 1 addition & 3 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
},
"overrides": [
{
"include": [
".vscode/**"
],
"include": [".vscode/**"],
"json": {
"parser": {
"allowComments": true,
Expand Down
Binary file modified bun.lockb
Binary file not shown.
22 changes: 17 additions & 5 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' }],
},
})
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion scripts/build.ts
Original file line number Diff line number Diff line change
@@ -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...')

Expand Down
40 changes: 25 additions & 15 deletions src/start.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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)

Expand All @@ -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/bS1H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JUxbQboH09TFt3yIG2h4Sa+4JDTEAlARJ6VWyrZKqsS3VxNb/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 })
Expand All @@ -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
Expand All @@ -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 })
Expand All @@ -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 {
Expand All @@ -105,8 +116,7 @@ export function startProxies(options?: Options): void {
options.forEach((option: Option) => {
startServer(option)
})
}
else {
} else {
startServer(options)
}
}
Expand Down
7 changes: 1 addition & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit 383854c

Please sign in to comment.