feat: implement Nginx project configuration generation and service management IPC handlers

This commit is contained in:
Ümit Tunç
2026-03-29 00:37:56 +03:00
parent e19f7e20fb
commit a6887106da
3 changed files with 43 additions and 20 deletions
+21 -19
View File
@@ -56,27 +56,29 @@ export function registerIpcHandlers(): void {
}
const projects = await projectService.getProjects()
const projectLocations = projects.map(p => {
const projectsConfDir = path.join(configService.getBasePath(), 'generated_configs', 'projects')
if (!fs.existsSync(projectsConfDir)) fs.mkdirSync(projectsConfDir, { recursive: true })
// Clean up old project configs
const existingFiles = fs.readdirSync(projectsConfDir)
for (const file of existingFiles) {
fs.unlinkSync(path.join(projectsConfDir, file))
}
for (const p of projects) {
const phpPort = portMappingService.getPhpPort(p.phpVersion)
const normalizedPath = p.path.replace(/\\/g, '/')
return `
location /${p.host}/ {
alias "${normalizedPath}/";
index index.php index.html;
try_files $uri $uri/ /${p.host}/index.php?$query_string;
await configService.generateConfig('nginx_project.conf.template', `projects/${p.host}.conf`, {
HOST: p.host,
PATH: normalizedPath,
PHP_PORT: phpPort.toString(),
CONF_DIR: confDir.replace(/\\/g, '/')
})
}
# Sadece .php değil, URI'nin tamamını eşleştirip dosya adını $1 içine alıyoruz
location ~ ^/${p.host}/(.*\.php)$ {
fastcgi_pass 127.0.0.1:${phpPort};
fastcgi_index index.php;
# Hatalı olan $request_filename yerine manuel path veriyoruz
fastcgi_param SCRIPT_FILENAME "${normalizedPath}/$1";
include "${confDir.replace(/\\/g, '/')}/fastcgi_params";
}
}`
}).join('\n')
const projectsInclusion = projects.length > 0
? `include "${projectsConfDir.replace(/\\/g, '/')}/*.conf";`
: ''
const configPath = await configService.generateConfig('nginx.conf.template', 'nginx.conf', {
PORT: settings.nginxPort,
@@ -85,7 +87,7 @@ export function registerIpcHandlers(): void {
LOG_DIR: logDir.replace(/\\/g, '/'),
CONF_DIR: confDir.replace(/\\/g, '/'),
PHPMYADMIN_DIR: phpMyAdminService.getPath().replace(/\\/g, '/'),
PROJECTS: projectLocations
PROJECTS: projectsInclusion
})
// Test config first with prefix