From 9ca4a55b19e8b64b301c2be91283425422f84e89 Mon Sep 17 00:00:00 2001 From: lunarthegrey Date: Mon, 8 Dec 2025 07:10:55 -0600 Subject: [PATCH] Switch Caddy configuration from JSON to YAML --- src/shadowbox/server/main.ts | 4 ++-- src/shadowbox/server/outline_caddy_server.ts | 15 +++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/shadowbox/server/main.ts b/src/shadowbox/server/main.ts index 300c3bfb..626acbcd 100644 --- a/src/shadowbox/server/main.ts +++ b/src/shadowbox/server/main.ts @@ -165,10 +165,10 @@ async function main() { } const caddyServer = new OutlineCaddyServer( getBinaryFilename('outline-caddy'), - getPersistentFilename('outline-caddy/config.json'), + getPersistentFilename('outline-caddy/config.yaml'), verbose ); - + // Configure listener defaults (e.g., WebSocket paths/ports) based on server configuration. const listenersConfig = serverConfig.data().listenersForNewAccessKeys; shadowsocksServer.configureListeners( diff --git a/src/shadowbox/server/outline_caddy_server.ts b/src/shadowbox/server/outline_caddy_server.ts index c56a490f..ae2d6b38 100644 --- a/src/shadowbox/server/outline_caddy_server.ts +++ b/src/shadowbox/server/outline_caddy_server.ts @@ -16,6 +16,7 @@ import * as child_process from 'child_process'; import * as path from 'path'; import * as mkdirp from 'mkdirp'; +import * as yaml from 'js-yaml'; import * as file from '../infrastructure/file'; import * as logging from '../infrastructure/logging'; @@ -76,15 +77,15 @@ export class OutlineCaddyServer implements OutlineCaddyController { } const configObject = this.buildConfig(payload, listenerSettings, websocketKeys); - const configJson = JSON.stringify(configObject, null, 2); - if (configJson === this.currentConfigHash) { + const configYaml = yaml.dump(configObject); + if (configYaml === this.currentConfigHash) { // No changes; nothing to do. return; } mkdirp.sync(path.dirname(this.configFilename)); - file.atomicWriteFileSync(this.configFilename, configJson); - this.currentConfigHash = configJson; + file.atomicWriteFileSync(this.configFilename, configYaml); + this.currentConfigHash = configYaml; this.shouldRun = true; await this.ensureStarted(); } @@ -122,7 +123,7 @@ export class OutlineCaddyServer implements OutlineCaddyController { private start(): Promise { return new Promise((resolve, reject) => { - const args = ['run', '--config', this.configFilename, '--adapter', 'json', '--watch']; + const args = ['run', '--config', this.configFilename, '--adapter', 'yaml', '--watch']; logging.info(`Starting outline-caddy with command: ${this.binaryFilename} ${args.join(' ')}`); const proc = child_process.spawn(this.binaryFilename, args, { stdio: ['ignore', 'pipe', 'pipe'], @@ -216,9 +217,7 @@ export class OutlineCaddyServer implements OutlineCaddyController { autoHttps = false; } const domain = requestedDomain; - const listenAddresses = autoHttps - ? [':80', ':443'] - : [`:${listenerSettings.listenPort}`]; + const listenAddresses = autoHttps ? [':80', ':443'] : [`:${listenerSettings.listenPort}`]; const hasStreamRoute = websocketKeys.length === 0 ||