2025-05-02 14:58:33 +00:00
|
|
|
import * as fs from 'fs';
|
|
|
|
import * as path from 'path';
|
2025-05-09 22:46:53 +00:00
|
|
|
import type { IAcmeOptions } from '../models/certificate-types.js';
|
2025-05-09 17:00:27 +00:00
|
|
|
import { ensureCertificateDirectory } from '../utils/certificate-helpers.js';
|
|
|
|
// We'll need to update this import when we move the Port80Handler
|
2025-05-09 21:52:46 +00:00
|
|
|
import { Port80Handler } from '../../http/port80/port80-handler.js';
|
2025-05-02 14:58:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Factory to create a Port80Handler with common setup.
|
|
|
|
* Ensures the certificate store directory exists and instantiates the handler.
|
|
|
|
* @param options Port80Handler configuration options
|
|
|
|
* @returns A new Port80Handler instance
|
|
|
|
*/
|
|
|
|
export function buildPort80Handler(
|
2025-05-09 22:46:53 +00:00
|
|
|
options: IAcmeOptions
|
2025-05-02 14:58:33 +00:00
|
|
|
): Port80Handler {
|
|
|
|
if (options.certificateStore) {
|
2025-05-09 17:00:27 +00:00
|
|
|
ensureCertificateDirectory(options.certificateStore);
|
|
|
|
console.log(`Ensured certificate store directory: ${options.certificateStore}`);
|
2025-05-02 14:58:33 +00:00
|
|
|
}
|
|
|
|
return new Port80Handler(options);
|
2025-05-09 17:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates default ACME options with sensible defaults
|
|
|
|
* @param email Account email for ACME provider
|
|
|
|
* @param certificateStore Path to store certificates
|
|
|
|
* @param useProduction Whether to use production ACME servers
|
|
|
|
* @returns Configured ACME options
|
|
|
|
*/
|
|
|
|
export function createDefaultAcmeOptions(
|
|
|
|
email: string,
|
|
|
|
certificateStore: string,
|
|
|
|
useProduction: boolean = false
|
2025-05-09 22:46:53 +00:00
|
|
|
): IAcmeOptions {
|
2025-05-09 17:00:27 +00:00
|
|
|
return {
|
|
|
|
accountEmail: email,
|
|
|
|
enabled: true,
|
|
|
|
port: 80,
|
|
|
|
useProduction,
|
|
|
|
httpsRedirectPort: 443,
|
|
|
|
renewThresholdDays: 30,
|
|
|
|
renewCheckIntervalHours: 24,
|
|
|
|
autoRenew: true,
|
|
|
|
certificateStore,
|
|
|
|
skipConfiguredCerts: false
|
|
|
|
};
|
2025-05-02 14:58:33 +00:00
|
|
|
}
|