From d3c68d6c893eb16d4143eed0838a6871225ed1b0 Mon Sep 17 00:00:00 2001 From: Florian Sylvain Date: Thu, 22 Dec 2022 02:52:50 +0100 Subject: [PATCH] Added host address to .env --- README.md | 7 ++++--- cmd/main.go | 4 ++-- docker-compose.yml | 4 ++-- internal/auth.go | 2 +- web/admin-gui/src/utils/ping.ts | 11 ----------- web/admin-gui/src/views/Debug.vue | 20 ++++++++++++++------ web/admin-gui/src/views/Login.vue | 2 +- 7 files changed, 24 insertions(+), 26 deletions(-) delete mode 100644 web/admin-gui/src/utils/ping.ts diff --git a/README.md b/README.md index c282474..5a659a8 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,9 @@ docker-compose up TODO ## Environment variables - ./env - - API_PORT - - FRONT_PORT - - JWT_SECRET + - APP_HOST_ADDRESS + - APP_API_PORT + - APP_FRONT_PORT + - APP_JWT_SECRET ## Demo TODO \ No newline at end of file diff --git a/cmd/main.go b/cmd/main.go index f0cb3b0..10a73fc 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -9,7 +9,7 @@ import ( "github.com/joho/godotenv" ) -var ginMode = os.Getenv("GIN_MODE") +var ginMode = os.Getenv("APP_GIN_MODE") func initEnvVariables() { if godotenv.Load() != nil { @@ -67,7 +67,7 @@ func initGin() { initBasicRoutes(r) initArticlesRoutes(r) - r.Run(":" + os.Getenv("API_PORT")) + r.Run(":" + os.Getenv("APP_API_PORT")) } func main() { diff --git a/docker-compose.yml b/docker-compose.yml index 02886e1..c8b630d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,7 +7,7 @@ services: env_file: - .env ports: - - "${API_PORT}:${API_PORT}" + - "${APP_API_PORT}:${APP_API_PORT}" networks: - back-net frontend: @@ -18,7 +18,7 @@ services: env_file: - .env ports: - - "${FRONT_PORT}:80" + - "${APP_FRONT_PORT}:80" networks: - front-net db: diff --git a/internal/auth.go b/internal/auth.go index 7fe9996..934d0ee 100644 --- a/internal/auth.go +++ b/internal/auth.go @@ -19,7 +19,7 @@ var UsersLocation = Location{Database: "gohcms", Collection: "users"} var AuthMiddleware, _ = jwt.New(&jwt.GinJWTMiddleware{ Realm: "GohCMS", - Key: []byte(os.Getenv("JWT_SECRET")), + Key: []byte(os.Getenv("APP_JWT_SECRET")), Timeout: time.Hour, MaxRefresh: time.Hour, Authenticator: JWTAuthenticator, diff --git a/web/admin-gui/src/utils/ping.ts b/web/admin-gui/src/utils/ping.ts deleted file mode 100644 index 976a84b..0000000 --- a/web/admin-gui/src/utils/ping.ts +++ /dev/null @@ -1,11 +0,0 @@ -export interface Pong { - message: string; -} - -export async function pingApi(): Promise { - let result: String = '' - await fetch('http://localhost:8080/ping') - .then(response => response.json()) - .then(jsonResponse => result = jsonResponse.message) - return result -} \ No newline at end of file diff --git a/web/admin-gui/src/views/Debug.vue b/web/admin-gui/src/views/Debug.vue index d41bc76..a53c4c3 100644 --- a/web/admin-gui/src/views/Debug.vue +++ b/web/admin-gui/src/views/Debug.vue @@ -6,8 +6,18 @@ import { ref } from 'vue'; const email = ref('') const password = ref('') +const baseURL = `http://${__APP_ENV__.APP_HOST_ADDRESS}:${__APP_ENV__.APP_API_PORT}` + function getArticles() { - fetch(`http://localhost:${__APP_ENV__.API_PORT}/articles/`, { + fetch(`${baseURL}/articles/`, { + headers: { "Authorization": `Bearer ${useAuthStore().token}` } + }) + .then(response => response.json()) + .then(result => console.log(result)) +} + +function ping() { + fetch(`${baseURL}/ping/`, { headers: { "Authorization": `Bearer ${useAuthStore().token}` } }) .then(response => response.json()) @@ -25,7 +35,7 @@ function jwtHandler(apiResponse: jwtFormat): void { } function login(email: string, password: string): void { - fetch(`http://localhost:${__APP_ENV__.API_PORT}/login/`, { + fetch(`${baseURL}/login/`, { method: "POST", body: JSON.stringify({ email: email, @@ -54,10 +64,8 @@ function login(email: string, password: string): void {
- - - - + +
diff --git a/web/admin-gui/src/views/Login.vue b/web/admin-gui/src/views/Login.vue index b2f82c1..b9f0929 100644 --- a/web/admin-gui/src/views/Login.vue +++ b/web/admin-gui/src/views/Login.vue @@ -18,7 +18,7 @@ function jwtHandler(apiResponse: jwtFormat): void { //TODO rempalcer tous les :8080 par la var d'env du port de l'API (sinon c un peu dommage) function login(email: string, password: string): void { - fetch(`http://localhost:${__APP_ENV__.API_PORT}/login/`, { + fetch(`http://${__APP_ENV__.APP_HOST_ADDRESS}:${__APP_ENV__.APP_API_PORT}/login/`, { method: "POST", body: JSON.stringify({ email: email,