feat: add dockerized 3proxy control plane backend
This commit is contained in:
32
server/index.ts
Normal file
32
server/index.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import path from 'node:path';
|
||||
import fs from 'node:fs/promises';
|
||||
import { createApp } from './app';
|
||||
import { buildRuntimePaths, render3proxyConfig } from './lib/config';
|
||||
import { ThreeProxyManager } from './lib/runtime';
|
||||
import { StateStore } from './lib/store';
|
||||
|
||||
const port = Number(process.env.PORT ?? '3000');
|
||||
const runtimeRootDir = path.resolve(process.env.RUNTIME_DIR ?? 'runtime');
|
||||
const statePath = path.join(runtimeRootDir, 'state', 'panel-state.json');
|
||||
const binaryPath = path.resolve(process.env.THREEPROXY_BINARY ?? '/usr/local/bin/3proxy');
|
||||
const autoStart = process.env.AUTO_START_3PROXY === 'true';
|
||||
|
||||
const store = new StateStore(statePath);
|
||||
const runtimePaths = buildRuntimePaths(runtimeRootDir);
|
||||
const runtime = new ThreeProxyManager(binaryPath, runtimePaths.configPath, runtimePaths, autoStart);
|
||||
|
||||
async function main() {
|
||||
const initialState = await store.read();
|
||||
await fs.mkdir(path.dirname(runtimePaths.configPath), { recursive: true });
|
||||
await fs.writeFile(runtimePaths.configPath, render3proxyConfig(initialState, runtimePaths), 'utf8');
|
||||
await runtime.initialize();
|
||||
const app = createApp({ store, runtime, runtimeRootDir });
|
||||
app.listen(port, () => {
|
||||
console.log(`Panel server listening on http://0.0.0.0:${port}`);
|
||||
});
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error(error);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
Reference in New Issue
Block a user