update
This commit is contained in:
@ -39,6 +39,13 @@ export interface IDcRouterOptions {
|
||||
|
||||
/** DNS server configuration */
|
||||
dnsServerConfig?: plugins.smartdns.IDnsServerOptions;
|
||||
|
||||
/** DNS challenge configuration for ACME (optional) */
|
||||
dnsChallenge?: {
|
||||
/** Cloudflare API key for DNS challenges */
|
||||
cloudflareApiKey?: string;
|
||||
/** Other DNS providers can be added here */
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,6 +118,7 @@ export class DcRouter {
|
||||
* Set up SmartProxy with direct configuration and automatic email routes
|
||||
*/
|
||||
private async setupSmartProxy(): Promise<void> {
|
||||
console.log('[DcRouter] Setting up SmartProxy...');
|
||||
let routes: plugins.smartproxy.IRouteConfig[] = [];
|
||||
let acmeConfig: plugins.smartproxy.IAcmeOptions | undefined;
|
||||
|
||||
@ -118,6 +126,8 @@ export class DcRouter {
|
||||
if (this.options.smartProxyConfig) {
|
||||
routes = this.options.smartProxyConfig.routes || [];
|
||||
acmeConfig = this.options.smartProxyConfig.acme;
|
||||
console.log(`[DcRouter] Found ${routes.length} routes in config`);
|
||||
console.log(`[DcRouter] ACME config present: ${!!acmeConfig}`);
|
||||
}
|
||||
|
||||
// If email config exists, automatically add email routes
|
||||
@ -137,6 +147,15 @@ export class DcRouter {
|
||||
};
|
||||
}
|
||||
|
||||
// Configure DNS challenge if available
|
||||
let challengeHandlers: any[] = [];
|
||||
if (this.options.dnsChallenge?.cloudflareApiKey) {
|
||||
console.log('Configuring Cloudflare DNS challenge for ACME');
|
||||
const cloudflareAccount = new plugins.cloudflare.CloudflareAccount(this.options.dnsChallenge.cloudflareApiKey);
|
||||
const dns01Handler = new plugins.smartacme.handlers.Dns01Handler(cloudflareAccount);
|
||||
challengeHandlers.push(dns01Handler);
|
||||
}
|
||||
|
||||
// If we have routes or need a basic SmartProxy instance, create it
|
||||
if (routes.length > 0 || this.options.smartProxyConfig) {
|
||||
console.log('Setting up SmartProxy with combined configuration');
|
||||
@ -148,26 +167,48 @@ export class DcRouter {
|
||||
acme: acmeConfig
|
||||
};
|
||||
|
||||
// If we have DNS challenge handlers, enhance the config
|
||||
if (challengeHandlers.length > 0) {
|
||||
// We'll need to pass this to SmartProxy somehow
|
||||
// For now, we'll set it as a property
|
||||
(smartProxyConfig as any).acmeChallengeHandlers = challengeHandlers;
|
||||
(smartProxyConfig as any).acmeChallengePriority = ['dns-01', 'http-01'];
|
||||
}
|
||||
|
||||
// Create SmartProxy instance
|
||||
console.log('[DcRouter] Creating SmartProxy instance with config:', JSON.stringify({
|
||||
routeCount: smartProxyConfig.routes?.length,
|
||||
acmeEnabled: smartProxyConfig.acme?.enabled,
|
||||
acmeEmail: smartProxyConfig.acme?.email,
|
||||
certProvisionFunction: !!smartProxyConfig.certProvisionFunction
|
||||
}, null, 2));
|
||||
|
||||
this.smartProxy = new plugins.smartproxy.SmartProxy(smartProxyConfig);
|
||||
|
||||
// Set up event listeners
|
||||
this.smartProxy.on('error', (err) => {
|
||||
console.error('SmartProxy error:', err);
|
||||
console.error('[DcRouter] SmartProxy error:', err);
|
||||
console.error('[DcRouter] Error stack:', err.stack);
|
||||
});
|
||||
|
||||
if (acmeConfig) {
|
||||
this.smartProxy.on('certificate-issued', (event) => {
|
||||
console.log(`Certificate issued for ${event.domain}, expires ${event.expiryDate}`);
|
||||
console.log(`[DcRouter] Certificate issued for ${event.domain}, expires ${event.expiryDate}`);
|
||||
});
|
||||
|
||||
this.smartProxy.on('certificate-renewed', (event) => {
|
||||
console.log(`Certificate renewed for ${event.domain}, expires ${event.expiryDate}`);
|
||||
console.log(`[DcRouter] Certificate renewed for ${event.domain}, expires ${event.expiryDate}`);
|
||||
});
|
||||
|
||||
this.smartProxy.on('certificate-failed', (event) => {
|
||||
console.error(`[DcRouter] Certificate failed for ${event.domain}:`, event.error);
|
||||
});
|
||||
}
|
||||
|
||||
// Start SmartProxy
|
||||
console.log('[DcRouter] Starting SmartProxy...');
|
||||
await this.smartProxy.start();
|
||||
console.log('[DcRouter] SmartProxy started successfully');
|
||||
|
||||
console.log(`SmartProxy started with ${routes.length} routes`);
|
||||
}
|
||||
|
Reference in New Issue
Block a user