Skip to content

Commit 543b93c

Browse files
committed
implements "transit"
0 parents  commit 543b93c

19 files changed

+2014
-0
lines changed

.github/workflows/main.yml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Build Transit
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Setup Bun
15+
uses: oven-sh/setup-bun@v1
16+
with:
17+
bun-version: latest
18+
19+
- name: Install dependencies
20+
run: bun install
21+
22+
- name: Build
23+
run: |
24+
mkdir -p bin
25+
bun run build-linux-x64
26+
bun run build-linux-arm64
27+
bun run build-windows-x64
28+
29+
- name: Upload Linux x64
30+
uses: actions/upload-artifact@v4
31+
with:
32+
name: transit-linux-x64
33+
path: bin/transit-linux-x64
34+
35+
- name: Upload Linux ARM64
36+
uses: actions/upload-artifact@v4
37+
with:
38+
name: transit-linux-arm64
39+
path: bin/transit-linux-arm64
40+
41+
- name: Upload Windows x64
42+
uses: actions/upload-artifact@v4
43+
with:
44+
name: transit-windows-x64
45+
path: bin/transit-windows-x64.exe

.gitignore

+182
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
2+
3+
bin/
4+
logs/
5+
plugins/
6+
config.yml
7+
transit
8+
transit.exe
9+
10+
# Logs
11+
12+
logs
13+
_.log
14+
npm-debug.log_
15+
yarn-debug.log*
16+
yarn-error.log*
17+
lerna-debug.log*
18+
.pnpm-debug.log*
19+
20+
# Caches
21+
22+
.cache
23+
24+
# Diagnostic reports (https://nodejs.org/api/report.html)
25+
26+
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
27+
28+
# Runtime data
29+
30+
pids
31+
_.pid
32+
_.seed
33+
*.pid.lock
34+
35+
# Directory for instrumented libs generated by jscoverage/JSCover
36+
37+
lib-cov
38+
39+
# Coverage directory used by tools like istanbul
40+
41+
coverage
42+
*.lcov
43+
44+
# nyc test coverage
45+
46+
.nyc_output
47+
48+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
49+
50+
.grunt
51+
52+
# Bower dependency directory (https://bower.io/)
53+
54+
bower_components
55+
56+
# node-waf configuration
57+
58+
.lock-wscript
59+
60+
# Compiled binary addons (https://nodejs.org/api/addons.html)
61+
62+
build/Release
63+
64+
# Dependency directories
65+
66+
node_modules/
67+
jspm_packages/
68+
69+
# Snowpack dependency directory (https://snowpack.dev/)
70+
71+
web_modules/
72+
73+
# TypeScript cache
74+
75+
*.tsbuildinfo
76+
77+
# Optional npm cache directory
78+
79+
.npm
80+
81+
# Optional eslint cache
82+
83+
.eslintcache
84+
85+
# Optional stylelint cache
86+
87+
.stylelintcache
88+
89+
# Microbundle cache
90+
91+
.rpt2_cache/
92+
.rts2_cache_cjs/
93+
.rts2_cache_es/
94+
.rts2_cache_umd/
95+
96+
# Optional REPL history
97+
98+
.node_repl_history
99+
100+
# Output of 'npm pack'
101+
102+
*.tgz
103+
104+
# Yarn Integrity file
105+
106+
.yarn-integrity
107+
108+
# dotenv environment variable files
109+
110+
.env
111+
.env.development.local
112+
.env.test.local
113+
.env.production.local
114+
.env.local
115+
116+
# parcel-bundler cache (https://parceljs.org/)
117+
118+
.parcel-cache
119+
120+
# Next.js build output
121+
122+
.next
123+
out
124+
125+
# Nuxt.js build / generate output
126+
127+
.nuxt
128+
dist
129+
130+
# Gatsby files
131+
132+
# Comment in the public line in if your project uses Gatsby and not Next.js
133+
134+
# https://nextjs.org/blog/next-9-1#public-directory-support
135+
136+
# public
137+
138+
# vuepress build output
139+
140+
.vuepress/dist
141+
142+
# vuepress v2.x temp and cache directory
143+
144+
.temp
145+
146+
# Docusaurus cache and generated files
147+
148+
.docusaurus
149+
150+
# Serverless directories
151+
152+
.serverless/
153+
154+
# FuseBox cache
155+
156+
.fusebox/
157+
158+
# DynamoDB Local files
159+
160+
.dynamodb/
161+
162+
# TernJS port file
163+
164+
.tern-port
165+
166+
# Stores VSCode versions used for testing VSCode extensions
167+
168+
.vscode-test
169+
170+
# yarn v2
171+
172+
.yarn/cache
173+
.yarn/unplugged
174+
.yarn/build-state.yml
175+
.yarn/install-state.gz
176+
.pnp.*
177+
178+
# IntelliJ based IDEs
179+
.idea
180+
181+
# Finder (MacOS) folder config
182+
.DS_Store

.prettierrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"useTabs": true,
3+
"semi": false,
4+
"singleQuote": true,
5+
"arrowParens": "avoid"
6+
}

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Transit
2+
3+
高性能 Minecraft 反向代理,使用 TypeScript 和 Bun 编写。
4+
5+
```shell
6+
cd transit
7+
bun install
8+
bun start
9+
```

bun.lockb

34.4 KB
Binary file not shown.

config.example.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
inbound:
2+
bind: 0.0.0.0:25565
3+
routes:
4+
- host: a.example.com
5+
destination: 127.0.0.1:25566
6+
- host: b.example.com
7+
destination: mc.hypixel.net
8+
rewriteHost: true

package.json

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "transit",
3+
"module": "src/index.ts",
4+
"type": "module",
5+
"devDependencies": {
6+
"@types/bun": "latest"
7+
},
8+
"peerDependencies": {
9+
"typescript": "^5.0.0"
10+
},
11+
"dependencies": {
12+
"@hownetworks/ipv46": "^2.1.0",
13+
"@types/micromatch": "^4.0.9",
14+
"@types/node": "^22.7.9",
15+
"mc-chat-format": "^1.2.2",
16+
"micromatch": "^4.0.8",
17+
"pino": "^9.5.0",
18+
"pino-pretty": "^11.3.0",
19+
"proxy-protocol-js": "^4.0.6",
20+
"socket.io-client": "^4.8.1",
21+
"typescript-result": "^3.0.0",
22+
"uint8array-extras": "^1.4.0",
23+
"unborn-mcproto": "^0.13.0",
24+
"uuidv4": "^6.2.13",
25+
"yaml": "^2.6.0",
26+
"zod": "^3.23.8",
27+
"zod-validation-error": "^3.4.0"
28+
},
29+
"scripts": {
30+
"start": "bun run src/index.ts",
31+
"dev": "bun run --hot src/index.ts",
32+
"build-linux-x64": "bun build --compile --minify --sourcemap --target=bun-linux-x64 src/index.ts --outfile bin/transit-linux-x64",
33+
"build-linux-arm64": "bun build --compile --minify --sourcemap --target=bun-linux-arm64 src/index.ts --outfile bin/transit-linux-arm64",
34+
"build-darwin-x64": "bun build --compile --minify --sourcemap --target=bun-darwin-x64 src/index",
35+
"build-darwin-arm64": "bun build --compile --minify --sourcemap --target=bun-darwin-arm64 src/index.ts --outfile bin/transit-darwin-arm64",
36+
"build-windows-x64": "bun build --compile --minify --sourcemap --target=bun-windows-x64 src/index.ts --outfile bin/transit-windows-x64.exe",
37+
"build-all": "bun run build-linux-x64 && bun run build-linux-arm64 && bun run build-darwin-x64 && bun run build-darwin-arm64 && bun run build-windows-x64",
38+
"build": "bun build --compile --minify --sourcemap src/index.ts --outfile transit"
39+
},
40+
"patchedDependencies": {
41+
"@hownetworks/[email protected]": "patches/@hownetworks%[email protected]"
42+
}
43+
}
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
diff --git a/dist/ipv46.d.ts b/dist/ipv46.d.ts
2+
index 715b1110d69075e587d3859af8e9ca9f7bd59b21..b39923e2ed4ce9f381c76167d19e58c94694908c 100644
3+
--- a/dist/ipv46.d.ts
4+
+++ b/dist/ipv46.d.ts
5+
@@ -2,7 +2,7 @@ export declare class IPv4 {
6+
static parse(string: string): IPv4 | null;
7+
static cmp(a: IPv4, b: IPv4): number;
8+
readonly version = 4;
9+
- private readonly _bytes;
10+
+ public readonly _bytes;
11+
private _string;
12+
private constructor();
13+
toString(): string;
14+
@@ -12,7 +12,7 @@ export declare class IPv6 {
15+
static parse(string: string): IPv6 | null;
16+
static cmp(a: IPv6, b: IPv6): number;
17+
readonly version = 6;
18+
- private readonly _words;
19+
+ public readonly _words;
20+
private _string;
21+
private constructor();
22+
toString(): string;

src/builtin-plugins/router.ts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { isMatch } from 'micromatch'
2+
import { LoginResultType, type Context } from '../plugins'
3+
4+
export const name = 'router'
5+
6+
// 为了方便,直接从 ctx.fullConfig 中获取配置
7+
// 而不是定义自己的配置模式
8+
9+
export const apply = (ctx: Context) => {
10+
logger.info(`Router plugin loaded: ${ctx.fullConfig.routes.length} route(s)`)
11+
12+
ctx.on('login', async (ctx: Context, _next: Function) => {
13+
const route = ctx.fullConfig.routes.find(route =>
14+
isMatch(ctx.host!, route.host)
15+
)
16+
if (route) {
17+
logger.info(`Routing ${ctx.host} to ${route.destination}`)
18+
return {
19+
type: LoginResultType.PASS,
20+
outbound: {
21+
destination: route.destination,
22+
rewriteHost: route.rewriteHost,
23+
proxyProtocol: route.proxyProtocol,
24+
},
25+
}
26+
}
27+
return _next()
28+
})
29+
30+
ctx.on('motd', async (ctx: Context, _next: Function) => {
31+
// 读取 ctx.fullConfig.motd 字段
32+
if (ctx.fullConfig.motd) {
33+
return ctx.fullConfig.motd
34+
}
35+
return _next()
36+
})
37+
}

0 commit comments

Comments
 (0)