From 006c01c97e1b0d6a22cbd7d9ae4170bc2b556254 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Seif=20Lotfy=20=D8=B3=D9=8A=D9=81=20=D9=84=D8=B7=D9=81?= =?UTF-8?q?=D9=8A?= Date: Thu, 13 Oct 2016 00:00:53 +0200 Subject: [PATCH] Change default API URL from localhost to 127.0.0.1 (#153) * Change host from localhost to 127.0.0.1 * change unit tests to also use 127.0.0.1 instead of localhost --- api/runner/async_runner_test.go | 18 +++++++++--------- api/server/server_test.go | 4 ++-- api/swagger.yml | 2 +- main.go | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/api/runner/async_runner_test.go b/api/runner/async_runner_test.go index 4b9b2dfae..f4975b71f 100644 --- a/api/runner/async_runner_test.go +++ b/api/runner/async_runner_test.go @@ -169,15 +169,15 @@ func TestTasksrvURL(t *testing.T) { tests := []struct { port, in, out string }{ - {"8080", "//localhost", "http://localhost:8080/tasks"}, - {"8080", "//localhost/", "http://localhost:8080/tasks"}, - {"8080", "//localhost:8081", "http://localhost:8081/tasks"}, - {"8080", "//localhost:8081/", "http://localhost:8081/tasks"}, - {"8080", "http://localhost", "http://localhost:8080/tasks"}, - {"8080", "http://localhost/", "http://localhost:8080/tasks"}, - {"8080", "http://localhost:8081", "http://localhost:8081/tasks"}, - {"8080", "http://localhost:8081/", "http://localhost:8081/tasks"}, - {"8080", "http://localhost:8081/endpoint", "http://localhost:8081/endpoint"}, + {"8080", "//127.0.0.1", "http://127.0.0.1:8080/tasks"}, + {"8080", "//127.0.0.1/", "http://127.0.0.1:8080/tasks"}, + {"8080", "//127.0.0.1:8081", "http://127.0.0.1:8081/tasks"}, + {"8080", "//127.0.0.1:8081/", "http://127.0.0.1:8081/tasks"}, + {"8080", "http://127.0.0.1", "http://127.0.0.1:8080/tasks"}, + {"8080", "http://127.0.0.1/", "http://127.0.0.1:8080/tasks"}, + {"8080", "http://127.0.0.1:8081", "http://127.0.0.1:8081/tasks"}, + {"8080", "http://127.0.0.1:8081/", "http://127.0.0.1:8081/tasks"}, + {"8080", "http://127.0.0.1:8081/endpoint", "http://127.0.0.1:8081/endpoint"}, } for _, tt := range tests { diff --git a/api/server/server_test.go b/api/server/server_test.go index e821db2dd..e4b7b020b 100644 --- a/api/server/server_test.go +++ b/api/server/server_test.go @@ -38,7 +38,7 @@ func testRouter() *gin.Engine { } func routerRequest(t *testing.T, router *gin.Engine, method, path string, body io.Reader) (*http.Request, *httptest.ResponseRecorder) { - req, err := http.NewRequest(method, "http://localhost:8080"+path, body) + req, err := http.NewRequest(method, "http://127.0.0.1:8080"+path, body) if err != nil { t.Fatalf("Test: Could not create %s request to %s: %v", method, path, err) } @@ -50,7 +50,7 @@ func routerRequest(t *testing.T, router *gin.Engine, method, path string, body i } func newRouterRequest(t *testing.T, method, path string, body io.Reader) (*http.Request, *httptest.ResponseRecorder) { - req, err := http.NewRequest(method, "http://localhost:8080"+path, body) + req, err := http.NewRequest(method, "http://127.0.0.1:8080"+path, body) if err != nil { t.Fatalf("Test: Could not create %s request to %s: %v", method, path, err) } diff --git a/api/swagger.yml b/api/swagger.yml index aace1bcbd..92768c618 100644 --- a/api/swagger.yml +++ b/api/swagger.yml @@ -8,7 +8,7 @@ info: description: version: "0.0.1" # the domain of the service -host: "localhost:8080" +host: "127.0.0.1:8080" # array of all schemes that your API supports schemes: - https diff --git a/main.go b/main.go index 8d25244c5..8cddba3f7 100644 --- a/main.go +++ b/main.go @@ -35,7 +35,7 @@ func init() { viper.SetDefault(envMQ, fmt.Sprintf("bolt://%s/data/worker_mq.db", cwd)) viper.SetDefault(envDB, fmt.Sprintf("bolt://%s/data/bolt.db?bucket=funcs", cwd)) viper.SetDefault(envPort, 8080) - viper.SetDefault(envAPIURL, fmt.Sprintf("http://localhost:%d", viper.GetInt(envPort))) + viper.SetDefault(envAPIURL, fmt.Sprintf("http://127.0.0.1:%d", viper.GetInt(envPort))) viper.SetDefault(envNumAsync, 1) viper.SetConfigName("config") viper.AddConfigPath(".")