feat: add Apache server support with configuration templates and IPC integration
This commit is contained in:
+18
-2
@@ -159,6 +159,17 @@ async function rebuildApacheConfig(forceProjects: boolean = false): Promise<{ bi
|
||||
const rootPath = path.join(configService.getBasePath(), 'www')
|
||||
if (!fs.existsSync(rootPath)) fs.mkdirSync(rootPath, { recursive: true })
|
||||
|
||||
const configPath = path.join(configService.getBasePath(), 'generated_configs', 'httpd.conf')
|
||||
|
||||
// Check if manual edit exists
|
||||
if (fs.existsSync(configPath) && !forceProjects) {
|
||||
const content = fs.readFileSync(configPath, 'utf8')
|
||||
if (content.includes('# MANUAL_EDIT')) {
|
||||
console.log('Skipping Apache config generation (Manual Edit detected)')
|
||||
return { binPath, apacheDir, configPath }
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure directories exist
|
||||
const projectsConfDir = path.join(configService.getBasePath(), 'generated_configs', 'projects_apache')
|
||||
if (!fs.existsSync(projectsConfDir)) fs.mkdirSync(projectsConfDir, { recursive: true })
|
||||
@@ -187,7 +198,7 @@ async function rebuildApacheConfig(forceProjects: boolean = false): Promise<{ bi
|
||||
? `Include "${projectsConfDir.replace(/\\/g, '/')}/*.conf"`
|
||||
: ''
|
||||
|
||||
const configPath = await configService.generateConfig('httpd.conf.template', 'httpd.conf', {
|
||||
await configService.generateConfig('httpd.conf.template', 'httpd.conf', {
|
||||
PORT: settings.apachePort || '8080',
|
||||
LISTEN_ADDRESS: settings.allowRemoteAccess ? '0.0.0.0' : '127.0.0.1',
|
||||
PHP_PORT: settings.phpPort,
|
||||
@@ -778,7 +789,12 @@ export function registerIpcHandlers(): void {
|
||||
|
||||
ipcMain.handle('apache:config:save', async (_event, content) => {
|
||||
const configPath = path.join(configService.getBasePath(), 'generated_configs', 'httpd.conf')
|
||||
fs.writeFileSync(configPath, content)
|
||||
// Ensure manual edit marker is present
|
||||
let finalContent = content
|
||||
if (!finalContent.includes('# MANUAL_EDIT')) {
|
||||
finalContent = `# MANUAL_EDIT\n${finalContent}`
|
||||
}
|
||||
fs.writeFileSync(configPath, finalContent)
|
||||
return await restartApache()
|
||||
})
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ export class ConfigService {
|
||||
|
||||
for (const [key, value] of Object.entries(variables)) {
|
||||
const escapedValue = value.replace(/\\/g, '/') // Use forward slashes for cross-platform compatibility in configs
|
||||
content = content.replace(new RegExp(`{{${key}}}`, 'g'), escapedValue)
|
||||
content = content.replace(new RegExp(`{{${key}}}`, 'g'), () => escapedValue)
|
||||
}
|
||||
|
||||
fs.writeFileSync(targetPath, content)
|
||||
|
||||
Reference in New Issue
Block a user