Skip to content

Commit f8261c1

Browse files
authored
Rails node ports for UI (#2802)
* Provide better default ports for Node and Rails for --ui * add Port to launch plan * remove code which would overwrite user's choice of port
1 parent 2cd869f commit f8261c1

File tree

3 files changed

+10
-34
lines changed

3 files changed

+10
-34
lines changed

internal/command/launch/plan_builder.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ func buildManifest(ctx context.Context) (*LaunchManifest, *planBuildCache, error
120120
lp.Redis = plan.DefaultRedis(lp)
121121
planSource.redisSource = scannerSource
122122
}
123+
if srcInfo.Port != 0 {
124+
lp.HttpServicePort = srcInfo.Port
125+
}
123126
}
124127

125128
return &LaunchManifest{

scanner/jsFramework.go

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"os/exec"
1111
"path/filepath"
1212
"regexp"
13-
"strconv"
1413
"strings"
1514

1615
"github.com/blang/semver"
@@ -183,6 +182,9 @@ func configureJsFramework(sourceDir string, config *ScannerConfig) (*SourceInfo,
183182
srcInfo.SkipDatabase = true
184183
}
185184

185+
// default to port 3000
186+
srcInfo.Port = 3000
187+
186188
// While redundant and requires dual matenance, it has been a point of
187189
// confusion for many when the framework detected is listed as "NodeJS"
188190
// See flyapps/dockerfile-node for the actual framework detction.
@@ -191,6 +193,7 @@ func configureJsFramework(sourceDir string, config *ScannerConfig) (*SourceInfo,
191193
srcInfo.Family = "AdonisJS"
192194
} else if deps["gatsby"] != nil {
193195
srcInfo.Family = "Gatsby"
196+
srcInfo.Port = 8080
194197
} else if deps["@nestjs/core"] != nil {
195198
srcInfo.Family = "NestJS"
196199
} else if deps["next"] != nil {
@@ -345,21 +348,6 @@ func JsFrameworkCallback(appName string, srcInfo *SourceInfo, plan *plan.LaunchP
345348
}
346349
srcInfo.Family = family
347350

348-
// extract port
349-
port := 3000
350-
re = regexp.MustCompile(`(?m)^EXPOSE\s+(?P<port>\d+)`)
351-
m = re.FindStringSubmatch(string(dockerfile))
352-
353-
for i, name := range re.SubexpNames() {
354-
if len(m) > 0 && name == "port" {
355-
port, err = strconv.Atoi(m[i])
356-
if err != nil {
357-
panic(err)
358-
}
359-
}
360-
}
361-
srcInfo.Port = port
362-
363351
// provide some advice
364352
srcInfo.DeployDocs += fmt.Sprintf(`
365353
If you need custom packages installed, or have problems with your deployment

scanner/rails.go

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"os/exec"
88
"path/filepath"
99
"regexp"
10-
"strconv"
1110
"strings"
1211

1312
"github.com/pkg/errors"
@@ -73,6 +72,7 @@ func configureRails(sourceDir string, config *ScannerConfig) (*SourceInfo, error
7372
s := &SourceInfo{
7473
Family: "Rails",
7574
Callback: RailsCallback,
75+
Port: 3000,
7676
ConsoleCommand: "/rails/bin/rails console",
7777
AutoInstrumentErrors: true,
7878
}
@@ -282,24 +282,9 @@ func RailsCallback(appName string, srcInfo *SourceInfo, plan *plan.LaunchPlan) e
282282
return errors.Wrap(err, "Dockerfile not found")
283283
}
284284

285-
// extract port
286-
port := 3000
287-
re := regexp.MustCompile(`(?m)^EXPOSE\s+(?P<port>\d+)`)
288-
m := re.FindStringSubmatch(string(dockerfile))
289-
290-
for i, name := range re.SubexpNames() {
291-
if len(m) > 0 && name == "port" {
292-
port, err = strconv.Atoi(m[i])
293-
if err != nil {
294-
panic(err)
295-
}
296-
}
297-
}
298-
srcInfo.Port = port
299-
300285
// extract volume - handle both plain string and JSON format, but only allow one path
301-
re = regexp.MustCompile(`(?m)^VOLUME\s+(\[\s*")?(\/[\w\/]*?(\w+))("\s*\])?\s*$`)
302-
m = re.FindStringSubmatch(string(dockerfile))
286+
re := regexp.MustCompile(`(?m)^VOLUME\s+(\[\s*")?(\/[\w\/]*?(\w+))("\s*\])?\s*$`)
287+
m := re.FindStringSubmatch(string(dockerfile))
303288

304289
if len(m) > 0 {
305290
srcInfo.Volumes = []Volume{

0 commit comments

Comments
 (0)