Skip to content

Commit 383854c

Browse files
committed
chore: wip
1 parent e9e0feb commit 383854c

File tree

11 files changed

+74
-74
lines changed

11 files changed

+74
-74
lines changed

.github/renovate.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
{
2-
"extends": [
3-
"@ow3"
4-
]
2+
"extends": ["@ow3"]
53
}

.vscode/settings.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,8 @@
6868
"yaml",
6969
"toml"
7070
],
71-
"cSpell.ignorePaths": [
72-
"node_modules"
73-
],
74-
"cSpell.dictionaries": [
75-
"custom-dictionary"
76-
],
71+
"cSpell.ignorePaths": ["node_modules"],
72+
"cSpell.dictionaries": ["custom-dictionary"],
7773
"cSpell.diagnosticLevel": "Hint",
7874
"cSpell.customDictionaries": {
7975
"bun-plugin-env": {

bin/cli.ts

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import os from 'node:os'
2+
import { log } from '@stacksjs/logging'
23
import { CAC } from 'cac'
34
import { readFileSync, writeFileSync } from 'fs-extra'
4-
import { log } from '@stacksjs/logging'
5-
import { startProxy } from '../src/start'
6-
import { config } from '../src/config'
75
import { version } from '../package.json'
6+
import { config } from '../src/config'
7+
import { startProxy } from '../src/start'
88

99
const cli = new CAC('reverse-proxy')
1010

@@ -26,7 +26,9 @@ cli
2626
.example('reverse-proxy start --from localhost:3000 --to my-project.localhost')
2727
.example('reverse-proxy start --from localhost:3001 --to my-project.localhost/api')
2828
.example('reverse-proxy start --from localhost:3000 --to localhost:3001')
29-
.example('reverse-proxy start --from localhost:3000 --to my-project.test --keyPath /absolute/path/to/key --certPath /absolute/path/to/cert')
29+
.example(
30+
'reverse-proxy start --from localhost:3000 --to my-project.test --keyPath /absolute/path/to/key --certPath /absolute/path/to/cert',
31+
)
3032
.action(async (options?: Options) => {
3133
if (options?.from || options?.to) {
3234
startProxy({
@@ -49,27 +51,29 @@ cli
4951
certPath: options?.certPath,
5052
})
5153
}
52-
}
53-
else {
54+
} else {
5455
// eslint-disable-next-line no-console
5556
console.log('No proxies found in the config')
5657
}
5758
})
5859

5960
cli
60-
.command('update:etc-hosts', 'Update the /etc/hosts file with the proxy domains. Please note, this command requires sudo/admin permissions.')
61+
.command(
62+
'update:etc-hosts',
63+
'Update the /etc/hosts file with the proxy domains. Please note, this command requires sudo/admin permissions.',
64+
)
6165
.alias('update-etc-hosts')
6266
.example('sudo reverse-proxy update:etc-hosts')
6367
.example('sudo reverse-proxy update-etc-hosts')
6468
.action(async () => {
6569
log.info('Ensuring /etc/hosts file covers the proxy domain/s...')
6670

67-
const hostsFilePath = os.platform() === 'win32'
68-
? 'C:\\Windows\\System32\\drivers\\etc\\hosts'
69-
: '/etc/hosts'
71+
const hostsFilePath = os.platform() === 'win32' ? 'C:\\Windows\\System32\\drivers\\etc\\hosts' : '/etc/hosts'
7072

7173
if (config && typeof config === 'object') {
72-
const entriesToAdd = Object.entries(config).map(([from, to]) => `127.0.0.1 ${to} # reverse-proxy mapping for ${from}`)
74+
const entriesToAdd = Object.entries(config).map(
75+
([from, to]) => `127.0.0.1 ${to} # reverse-proxy mapping for ${from}`,
76+
)
7377
// Ensure "127.0.0.1 localhost" is in the array
7478
entriesToAdd.push('127.0.0.1 localhost # essential localhost mapping')
7579

@@ -86,39 +90,32 @@ cli
8690
// If not, append it
8791
currentHostsContent += `\n${entry}`
8892
updated = true
89-
}
90-
else {
93+
} else {
9194
log.info(`Entry for ${host} already exists in the hosts file.`)
9295
}
9396
}
9497

9598
if (updated) {
9699
writeFileSync(hostsFilePath, currentHostsContent, 'utf8')
97100
log.success('Hosts file updated with latest proxy domains.')
98-
}
99-
else {
101+
} else {
100102
log.info('No new entries were added to the hosts file.')
101103
}
102-
}
103-
catch (error: unknown) {
104+
} catch (error: unknown) {
104105
if ((error as NodeJS.ErrnoException).code === 'EACCES')
105106
console.error('Permission denied. Please run this command with administrative privileges.')
106-
else
107-
console.error(`An error occurred: ${(error as NodeJS.ErrnoException).message}`)
107+
else console.error(`An error occurred: ${(error as NodeJS.ErrnoException).message}`)
108108
}
109-
}
110-
else {
109+
} else {
111110
// eslint-disable-next-line no-console
112111
console.log('No proxies found. Is your config configured properly?')
113112
}
114113
})
115114

116-
cli
117-
.command('version', 'Show the version of the Reverse Proxy CLI')
118-
.action(() => {
119-
// eslint-disable-next-line no-console
120-
console.log(version)
121-
})
115+
cli.command('version', 'Show the version of the Reverse Proxy CLI').action(() => {
116+
// eslint-disable-next-line no-console
117+
console.log(version)
118+
})
122119

123120
cli.version(version)
124121
cli.help()

biome.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
},
66
"overrides": [
77
{
8-
"include": [
9-
".vscode/**"
10-
],
8+
"include": [".vscode/**"],
119
"json": {
1210
"parser": {
1311
"allowComments": true,

bun.lockb

0 Bytes
Binary file not shown.

commitlint.config.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const config = {
66
},
77
prompt: {
88
messages: {
9-
type: 'Select the type of change that you\'re committing:',
9+
type: "Select the type of change that you're committing:",
1010
scope: 'Select the SCOPE of this change (optional):',
1111
customScope: 'Select the SCOPE of this change:',
1212
subject: 'Write a SHORT, IMPERATIVE tense description of the change:\n',
@@ -22,12 +22,24 @@ const config = {
2222
{ value: 'fix', name: 'fix: 🐛 A bug fix', emoji: ':bug:' },
2323
{ value: 'docs', name: 'docs: 📝 Documentation only changes', emoji: ':memo:' },
2424
{ value: 'style', name: 'style: 💄 Changes that do not affect the meaning of the code', emoji: ':lipstick:' },
25-
{ value: 'refactor', name: 'refactor: ♻️ A code change that neither fixes a bug nor adds a feature', emoji: ':recycle:' },
25+
{
26+
value: 'refactor',
27+
name: 'refactor: ♻️ A code change that neither fixes a bug nor adds a feature',
28+
emoji: ':recycle:',
29+
},
2630
{ value: 'perf', name: 'perf: ⚡️ A code change that improves performance', emoji: ':zap:' },
27-
{ value: 'test', name: 'test: ✅ Adding missing tests or adjusting existing tests', emoji: ':white_check_mark:' },
28-
{ value: 'build', name: 'build: 📦️ Changes that affect the build system or external dependencies', emoji: ':package:' },
31+
{
32+
value: 'test',
33+
name: 'test: ✅ Adding missing tests or adjusting existing tests',
34+
emoji: ':white_check_mark:',
35+
},
36+
{
37+
value: 'build',
38+
name: 'build: 📦️ Changes that affect the build system or external dependencies',
39+
emoji: ':package:',
40+
},
2941
{ value: 'ci', name: 'ci: 🎡 Changes to our CI configuration files and scripts', emoji: ':ferris_wheel:' },
30-
{ value: 'chore', name: 'chore: 🔨 Other changes that don\'t modify src or test files', emoji: ':hammer:' },
42+
{ value: 'chore', name: "chore: 🔨 Other changes that don't modify src or test files", emoji: ':hammer:' },
3143
{ value: 'revert', name: 'revert: ⏪️ Reverts a previous commit', emoji: ':rewind:' },
3244
],
3345
useEmoji: false,

docs/.vitepress/config.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ export default defineConfig({
2121
},
2222
],
2323

24-
socialLinks: [
25-
{ icon: 'github', link: 'https://github.com/vuejs/vitepress' },
26-
],
24+
socialLinks: [{ icon: 'github', link: 'https://github.com/vuejs/vitepress' }],
2725
},
2826
})

package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@
4040
"bun-reverse-proxy": "./dist/cli.js",
4141
"reverse-proxy": "./dist/cli.js"
4242
},
43-
"files": [
44-
"dist",
45-
"scripts",
46-
"src"
47-
],
43+
"files": ["dist", "scripts", "src"],
4844
"scripts": {
4945
"build": "bun scripts/build.ts && bun run compile",
5046
"compile": "bun build ./bin/cli.ts --compile --external rollup --minify --sourcemap --outfile dist/reverse-proxy",

scripts/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from 'node:path'
2+
import { log } from '@stacksjs/logging'
23
import { $ } from 'bun'
34
import dts from 'bun-plugin-dts-auto'
4-
import { log } from '@stacksjs/logging'
55

66
log.info('Building...')
77

src/start.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import * as net from 'node:net'
21
import * as http from 'node:http'
32
import * as https from 'node:https'
3+
import * as net from 'node:net'
44
import { bold, dim, green, log } from '@stacksjs/cli'
55
import { version } from '../package.json'
66

@@ -18,7 +18,9 @@ export async function startServer(option: Option = { from: 'localhost:3000', to:
1818
log.debug('Starting Reverse Proxy Server')
1919

2020
// Parse the option.from URL to dynamically set hostname and port
21-
const fromUrl = new URL(option.from ? (option.from.startsWith('http') ? option.from : `http://${option.from}`) : 'http://localhost:3000')
21+
const fromUrl = new URL(
22+
option.from ? (option.from.startsWith('http') ? option.from : `http://${option.from}`) : 'http://localhost:3000',
23+
)
2224
const hostname = fromUrl.hostname
2325
const port = Number.parseInt(fromUrl.port) || (fromUrl.protocol === 'https:' ? 443 : 80)
2426

@@ -27,8 +29,10 @@ export async function startServer(option: Option = { from: 'localhost:3000', to:
2729
log.debug(`Successfully connected to ${option.from}`)
2830
socket.end()
2931

30-
const cert = '-----BEGIN CERTIFICATE-----\r\nMIIDBjCCAe6gAwIBAgIUAdYO7vc82qKcT2DJn7WXylTNN6kwDQYJKoZIhvcNAQEF\r\nBQAwLTELMAkGA1UEBhMCQVUxEzARBgNVBAgTClNvbWUtU3RhdGUxCTAHBgNVBAoT\r\nADAeFw0yNDAzMDkxNzUwMjZaFw0yNDAzMTAxNzUwMjZaMC0xCzAJBgNVBAYTAkFV\r\nMRMwEQYDVQQIEwpTb21lLVN0YXRlMQkwBwYDVQQKEwAwggEiMA0GCSqGSIb3DQEB\r\nAQUAA4IBDwAwggEKAoIBAQC0Nl+n9xusat7FvFn/7/NEXDn35I/T0cAiwesBbDDo\r\neXtM/iOfvTRqYS+1Kca9byC4kFuFW7cO8gsihHb2bV6YjgLkuDG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PRIVATE KEY-----\r\n'
3236

3337
// Proceed with setting up the reverse proxy after successful connection
3438
setupReverseProxy({ key, cert, hostname, port, option })
@@ -40,7 +44,13 @@ export async function startServer(option: Option = { from: 'localhost:3000', to:
4044
})
4145
}
4246

43-
export function setupReverseProxy({ key, cert, hostname, port, option }: { key?: string, cert?: string, hostname: string, port: number, option: Option }): void {
47+
export function setupReverseProxy({
48+
key,
49+
cert,
50+
hostname,
51+
port,
52+
option,
53+
}: { key?: string; cert?: string; hostname: string; port: number; option: Option }): void {
4454
log.debug('setupReverseProxy', { key, cert, hostname, port, option })
4555

4656
// This server will act as a reverse proxy
@@ -56,7 +66,7 @@ export function setupReverseProxy({ key, cert, hostname, port, option }: { key?:
5666

5767
// Create a request to the target server
5868
const proxyReq = http.request(options, (proxyRes) => {
59-
// Set the statusCode and headers from the proxied response
69+
// Set the statusCode and headers from the proxied response
6070
res.writeHead(proxyRes.statusCode || 500, proxyRes.headers)
6171
// Pipe the proxied response's body directly to the original response
6272
proxyRes.pipe(res, { end: true })
@@ -81,19 +91,20 @@ export function setupReverseProxy({ key, cert, hostname, port, option }: { key?:
8191
// eslint-disable-next-line no-console
8292
console.log('')
8393
// eslint-disable-next-line no-console
84-
console.log(` ${green('➜')} ${dim(option.from!)} ${dim('➜')} https://${option.to}`)
94+
console.log(` ${green('➜')} ${dim(option.from as string)} ${dim('➜')} https://${option.to}`)
8595
})
8696

8797
// http to https redirect
88-
if (option.httpsRedirect ?? true)
89-
startHttpRedirectServer()
98+
if (option.httpsRedirect ?? true) startHttpRedirectServer()
9099
}
91100

92101
export function startHttpRedirectServer(): void {
93-
http.createServer((req, res) => {
94-
res.writeHead(301, { Location: `https://${req.headers.host}${req.url}` })
95-
res.end()
96-
}).listen(80)
102+
http
103+
.createServer((req, res) => {
104+
res.writeHead(301, { Location: `https://${req.headers.host}${req.url}` })
105+
res.end()
106+
})
107+
.listen(80)
97108
}
98109

99110
export function startProxy(option?: Option): void {
@@ -105,8 +116,7 @@ export function startProxies(options?: Options): void {
105116
options.forEach((option: Option) => {
106117
startServer(option)
107118
})
108-
}
109-
else {
119+
} else {
110120
startServer(options)
111121
}
112122
}

0 commit comments

Comments
 (0)