Skip to content

Commit dcd5d8c

Browse files
authored
Merge pull request #29 from egmc/listen-option
add listen option
2 parents 2f6593d + aca9818 commit dcd5d8c

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Only PHP files within the `--target-dir` directory will be tracked.
110110

111111
### HTTP API
112112

113-
After starting, an HTTP server runs on port 8080 with the following endpoints:
113+
After starting, an HTTP server runs on port 8080 by default (configurable via `--listen`) with the following endpoints:
114114

115115
#### GET /v1/report
116116
Returns a report of PHP files in the target directory and their compilation status.

main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ const (
156156
var targetDir string
157157
var emitLogEvents bool
158158
var rewriteRuleFlags []string
159+
var listenAddr string
159160
var rewriteRules []RewriteRule
160161

161162
// RewriteRule holds a compiled regex and its replacement string
@@ -365,6 +366,8 @@ func init() {
365366
rootCmd.Flags().BoolVar(&emitLogEvents, "emit-log-events", false, "Enable emitting log events via OTLP")
366367
rootCmd.Flags().StringArrayVar(&rewriteRuleFlags, "compiled-path-rewrite-rule", nil,
367368
"Rewrite rule for compiled file paths (format: regex::replacement, can be specified multiple times)")
369+
rootCmd.Flags().StringVar(&listenAddr, "listen", ":8080",
370+
"HTTP server listen address (format: [host]:port, e.g. :8080, 127.0.0.1:8080, 0.0.0.0:9000)")
368371
}
369372

370373
func main() {
@@ -504,8 +507,8 @@ func run(cmd *cobra.Command, args []string) error {
504507
http.HandleFunc("/v1/report", handleReport)
505508
http.HandleFunc("/v1/stats", handleStats)
506509
go func() {
507-
slog.Info("Starting HTTP server on :8080")
508-
if err := http.ListenAndServe(":8080", nil); err != nil {
510+
slog.Info("Starting HTTP server", "listen", listenAddr)
511+
if err := http.ListenAndServe(listenAddr, nil); err != nil {
509512
slog.Error("HTTP server error", "error", err)
510513
}
511514
}()

0 commit comments

Comments
 (0)