Skip to content

Commit 6673f37

Browse files
committed
Run env_transforms before localhost rewrite
- Transforms now apply to original .env content - Localhost rewrite runs after, on transformed values - Fixes transforms that modify paths before domain swap
1 parent 8db6951 commit 6673f37

1 file changed

Lines changed: 21 additions & 21 deletions

File tree

cmd/service.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -232,27 +232,8 @@ var serviceUpCmd = &cobra.Command{
232232
continue
233233
}
234234

235-
// Replace http://localhost:PORT → https://domain only for declared env var prefixes
236-
localhostRe := regexp.MustCompile(`http://localhost:\d+`)
237-
rewritePrefixes := ctx.spec.Sync.EnvRewriteVars
238-
var modifiedLines []string
239-
for _, line := range strings.Split(envContent, "\n") {
240-
if len(rewritePrefixes) > 0 {
241-
for _, prefix := range rewritePrefixes {
242-
if strings.HasPrefix(line, prefix) {
243-
line = localhostRe.ReplaceAllString(line, domain)
244-
break
245-
}
246-
}
247-
} else {
248-
// No prefixes defined — rewrite all (backward compat)
249-
line = localhostRe.ReplaceAllString(line, domain)
250-
}
251-
modifiedLines = append(modifiedLines, line)
252-
}
253-
modified := strings.Join(modifiedLines, "\n")
254-
255-
// Apply env_transforms from velocity.yml
235+
// Apply env_transforms first (before localhost rewrite)
236+
modified := envContent
256237
for _, t := range ctx.spec.Sync.EnvTransforms {
257238
// Skip if scoped to specific services and this isn't one
258239
if len(t.Services) > 0 {
@@ -284,6 +265,25 @@ var serviceUpCmd = &cobra.Command{
284265
modified = re.ReplaceAllString(modified, repl)
285266
}
286267

268+
// Then replace http://localhost:PORT → https://domain for declared prefixes
269+
localhostRe := regexp.MustCompile(`http://localhost:\d+`)
270+
rewritePrefixes := ctx.spec.Sync.EnvRewriteVars
271+
var rewrittenLines []string
272+
for _, line := range strings.Split(modified, "\n") {
273+
if len(rewritePrefixes) > 0 {
274+
for _, prefix := range rewritePrefixes {
275+
if strings.HasPrefix(line, prefix) {
276+
line = localhostRe.ReplaceAllString(line, domain)
277+
break
278+
}
279+
}
280+
} else {
281+
line = localhostRe.ReplaceAllString(line, domain)
282+
}
283+
rewrittenLines = append(rewrittenLines, line)
284+
}
285+
modified = strings.Join(rewrittenLines, "\n")
286+
287287
changed := modified != envContent
288288
if !changed {
289289
continue

0 commit comments

Comments
 (0)