diff --git a/internal/service/component_batch.go b/internal/service/component_batch.go index beb61c5..ea9b58f 100644 --- a/internal/service/component_batch.go +++ b/internal/service/component_batch.go @@ -153,6 +153,30 @@ func (s *ComponentService) AddComponentBatch(ctx context.Context, projectID stri "DOMAIN": projectDomain, } + // For frontend apps, inject the primary service name/port for API proxy. + // Check the batch itself first (service not yet in DB), then fall back to DB. + if componentType.IsAppComponent() { + var svcName string + var svcPort int + for _, r := range codeReqs { + if domain.ComponentType(r.Type) == domain.ComponentTypeService { + svcName = r.Name + svcPort = r.Port + break + } + } + if svcName == "" { + if svc := s.findFirstServiceComponent(ctx, projectID); svc != nil { + svcName = svc.Name + svcPort = svc.Port + } + } + if svcName != "" { + vars["SERVICE_NAME"] = svcName + vars["SERVICE_PORT"] = strconv.Itoa(svcPort) + } + } + // Get component template files componentFiles, err := s.templateProvider.GetComponentFiles(ctx, req.Type, componentPath, vars) if err != nil {