|
1 | | -import { isAbsolute, extname, join, resolve, sep } from 'node:path' |
| 1 | +import { isAbsolute, extname, join, resolve, sep, relative } from 'node:path' |
2 | 2 | import { getFreePorts } from './network.js' |
3 | 3 |
|
4 | 4 | import { spawn, fork } from 'node:child_process' |
@@ -221,9 +221,25 @@ export function resolveServiceBuildInfo(service, name, opts: ServiceOptions) { |
221 | 221 |
|
222 | 222 | // Only include SSL if both files exist |
223 | 223 | if (existsSync(keyPath) && existsSync(certPath)) { |
| 224 | + // For desktop targets being built, adjust paths for ASAR packaging |
| 225 | + // Store paths that will work at runtime |
| 226 | + const adjustPathForDesktop = (path: string) => { |
| 227 | + if (!isDesktopTarget || !isBuildProcess) return path |
| 228 | + |
| 229 | + // Make path relative to root for packaging |
| 230 | + const relativePath = relative(root, path) |
| 231 | + |
| 232 | + // At runtime in Electron, these will be in extraResources |
| 233 | + // so we return a marker that will be resolved at runtime |
| 234 | + return `__RUNTIME_SSL__/${relativePath}` |
| 235 | + } |
| 236 | + |
224 | 237 | resolvedSSL = { |
225 | | - key: keyPath, |
226 | | - cert: certPath |
| 238 | + key: adjustPathForDesktop(keyPath), |
| 239 | + cert: adjustPathForDesktop(certPath), |
| 240 | + // Store original paths for build-time asset collection |
| 241 | + __keySource: keyPath, |
| 242 | + __certSource: certPath, |
227 | 243 | } |
228 | 244 | } else { |
229 | 245 | logger.warn(`SSL configuration provided but certificate files not found:`) |
@@ -393,12 +409,44 @@ export async function start( |
393 | 409 | // Get service-specific env variables |
394 | 410 | const serviceEnv = config.env && typeof config.env === 'object' ? config.env : {} |
395 | 411 |
|
| 412 | + // Helper to resolve runtime SSL paths |
| 413 | + function resolveRuntimePath(path: string): string { |
| 414 | + // If path contains runtime marker, resolve it |
| 415 | + if (path.startsWith('__RUNTIME_SSL__/')) { |
| 416 | + const relativePath = path.replace('__RUNTIME_SSL__/', '') |
| 417 | + |
| 418 | + // In Electron production, resolve from extraResources |
| 419 | + if (typeof process !== 'undefined' && process.resourcesPath) { |
| 420 | + const resolvedPath = resolve(process.resourcesPath, 'ssl', relativePath) |
| 421 | + logger.debug(`[${label}] SSL path resolved from resources: ${path} -> ${resolvedPath}`) |
| 422 | + return resolvedPath |
| 423 | + } |
| 424 | + |
| 425 | + // Fallback to original resolution (shouldn't happen) |
| 426 | + const resolvedPath = resolve(root, relativePath) |
| 427 | + logger.debug(`[${label}] SSL path resolved from root: ${path} -> ${resolvedPath}`) |
| 428 | + return resolvedPath |
| 429 | + } |
| 430 | + |
| 431 | + // In dev mode, paths should already be absolute |
| 432 | + logger.debug(`[${label}] SSL path used as-is: ${path}`) |
| 433 | + return path |
| 434 | + } |
| 435 | + |
396 | 436 | // Add SSL certificate paths to environment if configured |
397 | 437 | const sslEnv = config.ssl ? { |
398 | | - SSL_KEY_PATH: config.ssl.key, |
399 | | - SSL_CERT_PATH: config.ssl.cert, |
| 438 | + SSL_KEY_PATH: resolveRuntimePath(config.ssl.key), |
| 439 | + SSL_CERT_PATH: resolveRuntimePath(config.ssl.cert), |
400 | 440 | } : {} |
401 | 441 |
|
| 442 | + if (config.ssl) { |
| 443 | + logger.debug(`[${label}] SSL configuration:`) |
| 444 | + logger.debug(` - SSL_KEY_PATH: ${sslEnv.SSL_KEY_PATH}`) |
| 445 | + logger.debug(` - SSL_CERT_PATH: ${sslEnv.SSL_CERT_PATH}`) |
| 446 | + logger.debug(` - Key exists: ${existsSync(sslEnv.SSL_KEY_PATH)}`) |
| 447 | + logger.debug(` - Cert exists: ${existsSync(sslEnv.SSL_CERT_PATH)}`) |
| 448 | + } |
| 449 | + |
402 | 450 | // Share environment variables with the child process |
403 | 451 | const env = { |
404 | 452 | ...userEnv, |
|
0 commit comments