feat: implement Nginx project configuration template and IPC handlers for service management

This commit is contained in:
Ümit Tunç
2026-03-30 08:05:44 +03:00
parent 34366e5d78
commit 039d0a2782
2 changed files with 30 additions and 9 deletions
+22 -4
View File
@@ -56,12 +56,26 @@ async function rebuildNginxConfig(forceProjects: boolean = false): Promise<{ bin
const projects = await projectService.getProjects()
for (const p of projects) {
const projectConfPath = path.join(projectsConfDir, `${p.host}.conf`)
if (forceProjects || !fs.existsSync(projectConfPath)) {
let shouldGenerate = forceProjects || !fs.existsSync(projectConfPath)
// If file exists, check if it was manually edited
if (!shouldGenerate && fs.existsSync(projectConfPath)) {
const currentContent = fs.readFileSync(projectConfPath, 'utf8')
if (currentContent.includes('# MANUAL_EDIT')) {
shouldGenerate = false // Never overwrite manual edits during auto-rebuild
} else if (forceProjects) {
shouldGenerate = true
}
}
if (shouldGenerate) {
const phpPort = portMappingService.getPhpPort(p.phpVersion)
const normalizedPath = p.path.replace(/\\/g, '/')
// Ensure path ends with a slash for alias compatibility
const pathWithSlash = normalizedPath.endsWith('/') ? normalizedPath : `${normalizedPath}/`
await configService.generateConfig('nginx_project.conf.template', `projects/${p.host}.conf`, {
HOST: p.host,
PATH: normalizedPath,
PATH: pathWithSlash,
PHP_PORT: phpPort.toString(),
CONF_DIR: confDir.replace(/\\/g, '/')
})
@@ -510,8 +524,12 @@ export function registerIpcHandlers(): void {
ipcMain.handle('project:nginx:save', async (_event, host, content) => {
const configPath = path.join(configService.getBasePath(), 'generated_configs', 'projects', `${host}.conf`)
fs.writeFileSync(configPath, content)
// Full restart after manual project save
// 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 restartNginx()
})