Skip to content

Commit 4814944

Browse files
committed
Unmarshal port fields as strings
1 parent 62e792d commit 4814944

2 files changed

Lines changed: 16 additions & 17 deletions

File tree

main.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"os"
1717
"path"
1818
"path/filepath"
19-
"strconv"
2019
"strings"
2120
"time"
2221

@@ -34,9 +33,9 @@ type ServerSettings struct {
3433
UseInfinityServer bool `json:"useInfinityServer"`
3534
InfinityServerURL string `json:"infinityServerURL"`
3635
HandleLegacyRequests bool `json:"handleLegacyRequests"`
37-
ExternalLegacyPort int `json:"externalLegacyPort"`
38-
ProxyPort int `json:"proxyPort"`
39-
ServerHTTPPort int `json:"serverHTTPPort"`
36+
ExternalLegacyPort string `json:"externalLegacyPort"`
37+
ProxyPort string `json:"proxyPort"`
38+
ServerHTTPPort string `json:"serverHTTPPort"`
4039
UseMad4FP bool `json:"useMad4FP"`
4140
EnableHttpsProxy bool `json:"enableHttpsProxy"`
4241
AllowCrossDomain bool `json:"allowCrossDomain"`
@@ -88,9 +87,9 @@ func initServer() {
8887
useInfinityServer := flag.Bool("useInfinityServer", serverSettings.UseInfinityServer, "Whether to use the infinity server or not")
8988
infinityServerURL := flag.String("infinityServerURL", serverSettings.InfinityServerURL, "The URL of the infinity server")
9089
handleLegacyRequests := flag.Bool("handleLegacyRequests", serverSettings.HandleLegacyRequests, "Whether to handle legacy requests internally (true) or externally (false)")
91-
externalLegacyPort := flag.Int("externalLegacyPort", serverSettings.ExternalLegacyPort, "The port that the external legacy server is running on (if handling legacy is disabled).")
92-
proxyPort := flag.Int("proxyPort", serverSettings.ProxyPort, "proxy listen port")
93-
serverHttpPort := flag.Int("serverHttpPort", serverSettings.ServerHTTPPort, "zip server http listen port")
90+
externalLegacyPort := flag.String("externalLegacyPort", serverSettings.ExternalLegacyPort, "The port that the external legacy server is running on (if handling legacy is disabled).")
91+
proxyPort := flag.String("proxyPort", serverSettings.ProxyPort, "proxy listen port")
92+
serverHttpPort := flag.String("serverHttpPort", serverSettings.ServerHTTPPort, "zip server http listen port")
9493
useMad4FP := flag.Bool("UseMad4FP", serverSettings.UseMad4FP, "flag to turn on/off Mad4FP.")
9594
enableHttpsProxy := flag.Bool("enableHttpsProxy", serverSettings.EnableHttpsProxy, "Whether to enable HTTPS proxying or not")
9695
allowCrossDomain := flag.Bool("allowCrossDomain", serverSettings.AllowCrossDomain, "Whether to allow cross-domain requests")
@@ -153,8 +152,8 @@ func initServer() {
153152
// Setup the proxy
154153
proxy = goproxy.NewProxyHttpServer()
155154
proxy.Verbose = serverSettings.VerboseLogging
156-
fmt.Println("Proxy Server started on port", strconv.Itoa(serverSettings.ProxyPort))
157-
fmt.Println("Zip Server started on port", strconv.Itoa(serverSettings.ServerHTTPPort))
155+
fmt.Println("Proxy Server started on port", serverSettings.ProxyPort)
156+
fmt.Println("Zip Server started on port", serverSettings.ServerHTTPPort)
158157
}
159158

160159
func setContentType(r *http.Request, resp *http.Response) {
@@ -219,7 +218,7 @@ func handleRequest(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http
219218
Method: r.Method,
220219
URL: &url.URL{
221220
Scheme: "http",
222-
Host: "127.0.0.1:" + strconv.Itoa(serverSettings.ServerHTTPPort),
221+
Host: "127.0.0.1:" + serverSettings.ServerHTTPPort,
223222
Path: "content/" + r.URL.Host + r.URL.Path,
224223
RawQuery: r.URL.RawQuery,
225224
},
@@ -269,15 +268,15 @@ func handleRequest(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http
269268
proxyResp = resRecorder.Result()
270269
} else {
271270
// Set the Proxy URL and apply it to the Transpor layer so that the request respects the proxy.
272-
proxyURL, _ := url.Parse("http://127.0.0.1:" + strconv.Itoa(serverSettings.ExternalLegacyPort))
271+
proxyURL, _ := url.Parse("http://127.0.0.1:" + serverSettings.ExternalLegacyPort)
273272
proxy := http.ProxyURL(proxyURL)
274273
transport := &http.Transport{Proxy: proxy}
275274

276275
// A custom Dialer is required for the "localflash" urls, instead of using the DNS, we use this.
277276
transport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
278277
//Set Dialer timeout and keepalive to 30 seconds and force the address to localhost.
279278
dialer := &net.Dialer{Timeout: 30 * time.Second, KeepAlive: 30 * time.Second}
280-
addr = "127.0.0.1:" + strconv.Itoa(serverSettings.ExternalLegacyPort)
279+
addr = "127.0.0.1:" + serverSettings.ExternalLegacyPort
281280
return dialer.DialContext(ctx, network, addr)
282281
}
283282

@@ -368,7 +367,7 @@ XgVWIMrKj4T7p86bcxq4jdWDYUYpRd/2Og==
368367
go func() {
369368
//TODO: Update these to be modifiable in the properties json.
370369
//TODO: Also update the "fpProxy/api/" to be in the properties json.
371-
log.Fatal(http.ListenAndServe("127.0.0.1:"+strconv.Itoa(serverSettings.ServerHTTPPort),
370+
log.Fatal(http.ListenAndServe("127.0.0.1:"+serverSettings.ServerHTTPPort,
372371
zipfs.EmptyFileServer(
373372
serverSettings.ApiPrefix,
374373
"",
@@ -384,5 +383,5 @@ XgVWIMrKj4T7p86bcxq4jdWDYUYpRd/2Og==
384383
}()
385384

386385
// Start proxy server
387-
log.Fatal(http.ListenAndServe("127.0.0.1:"+strconv.Itoa(serverSettings.ProxyPort), http.AllowQuerySemicolons(proxy)))
386+
log.Fatal(http.ListenAndServe("127.0.0.1:"+serverSettings.ProxyPort, http.AllowQuerySemicolons(proxy)))
388387
}

proxySettings.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
"useInfinityServer": false,
99
"infinityServerURL": "https://infinity.unstable.life/Flashpoint/Legacy/htdocs/",
1010
"handleLegacyRequests": false,
11-
"externalLegacyPort": 22600,
12-
"proxyPort": 22500,
13-
"serverHTTPPort": 22501,
11+
"externalLegacyPort": "22600",
12+
"proxyPort": "22500",
13+
"serverHTTPPort": "22501",
1414
"useMad4FP": false,
1515
"enableHttpsProxy": false,
1616
"allowCrossDomain": true,

0 commit comments

Comments
 (0)