Fix yaml for dynamic keys

This commit is contained in:
lunarthegrey 2025-08-28 22:27:34 -05:00
parent b9dbf82f40
commit 05fb79c6ba
2 changed files with 21 additions and 9 deletions

View file

@ -393,7 +393,10 @@ export class ShadowsocksManagerService {
const domain = configData?.caddyWebServer?.domain || configData?.hostname;
const listenersConfig = configData?.listenersForNewAccessKeys;
if (domain && listenersConfig) {
logging.debug(`WebSocket key detected. Domain: ${domain}, Listeners config: ${JSON.stringify(listenersConfig)}`);
// Generate YAML even if listenersConfig is not fully configured, using defaults
if (domain) {
const serverWithWebSocket = this.shadowsocksServer as ShadowsocksServer & {
generateDynamicAccessKeyYaml?: (
proxyParams: {encryptionMethod: string; password: string},
@ -407,8 +410,8 @@ export class ShadowsocksManagerService {
const yamlConfig = serverWithWebSocket.generateDynamicAccessKeyYaml?.(
accessKey.proxyParams,
domain,
listenersConfig.websocketStream?.path || '/tcp',
listenersConfig.websocketPacket?.path || '/udp',
listenersConfig?.websocketStream?.path || '/tcp',
listenersConfig?.websocketPacket?.path || '/udp',
this.serverConfig.data()?.caddyWebServer?.autoHttps !== false
);

View file

@ -298,22 +298,23 @@ export class OutlineShadowsocksServer implements ShadowsocksServer {
const protocol = tls ? 'wss' : 'ws';
// Generate YAML configuration matching Outline client spec exactly
const config = {
transport: {
$type: 'tcpudp',
'$type': 'tcpudp',
tcp: {
$type: 'shadowsocks',
'$type': 'shadowsocks',
endpoint: {
$type: 'websocket',
'$type': 'websocket',
url: `${protocol}://${domain}${tcpPath}`
},
cipher: proxyParams.encryptionMethod,
secret: proxyParams.password
},
udp: {
$type: 'shadowsocks',
'$type': 'shadowsocks',
endpoint: {
$type: 'websocket',
'$type': 'websocket',
url: `${protocol}://${domain}${udpPath}`
},
cipher: proxyParams.encryptionMethod,
@ -322,7 +323,15 @@ export class OutlineShadowsocksServer implements ShadowsocksServer {
}
};
return jsyaml.safeDump(config, {sortKeys: true});
// Use specific YAML options to ensure proper formatting
return jsyaml.dump(config, {
indent: 2,
lineWidth: -1, // Don't wrap long lines
noRefs: true, // Don't use references
sortKeys: false, // Preserve key order
quotingType: '"', // Use double quotes when needed
forceQuotes: false // Don't quote all strings
});
}
private start() {