Added host address to .env

This commit is contained in:
Florian Sylvain
2022-12-22 02:52:50 +01:00
parent 659554c2a9
commit d3c68d6c89
7 changed files with 24 additions and 26 deletions
+4 -3
View File
@@ -12,8 +12,9 @@ docker-compose up
TODO TODO
## Environment variables ## Environment variables
- ./env - ./env
- API_PORT - APP_HOST_ADDRESS
- FRONT_PORT - APP_API_PORT
- JWT_SECRET - APP_FRONT_PORT
- APP_JWT_SECRET
## Demo ## Demo
TODO TODO
+2 -2
View File
@@ -9,7 +9,7 @@ import (
"github.com/joho/godotenv" "github.com/joho/godotenv"
) )
var ginMode = os.Getenv("GIN_MODE") var ginMode = os.Getenv("APP_GIN_MODE")
func initEnvVariables() { func initEnvVariables() {
if godotenv.Load() != nil { if godotenv.Load() != nil {
@@ -67,7 +67,7 @@ func initGin() {
initBasicRoutes(r) initBasicRoutes(r)
initArticlesRoutes(r) initArticlesRoutes(r)
r.Run(":" + os.Getenv("API_PORT")) r.Run(":" + os.Getenv("APP_API_PORT"))
} }
func main() { func main() {
+2 -2
View File
@@ -7,7 +7,7 @@ services:
env_file: env_file:
- .env - .env
ports: ports:
- "${API_PORT}:${API_PORT}" - "${APP_API_PORT}:${APP_API_PORT}"
networks: networks:
- back-net - back-net
frontend: frontend:
@@ -18,7 +18,7 @@ services:
env_file: env_file:
- .env - .env
ports: ports:
- "${FRONT_PORT}:80" - "${APP_FRONT_PORT}:80"
networks: networks:
- front-net - front-net
db: db:
+1 -1
View File
@@ -19,7 +19,7 @@ var UsersLocation = Location{Database: "gohcms", Collection: "users"}
var AuthMiddleware, _ = jwt.New(&jwt.GinJWTMiddleware{ var AuthMiddleware, _ = jwt.New(&jwt.GinJWTMiddleware{
Realm: "GohCMS", Realm: "GohCMS",
Key: []byte(os.Getenv("JWT_SECRET")), Key: []byte(os.Getenv("APP_JWT_SECRET")),
Timeout: time.Hour, Timeout: time.Hour,
MaxRefresh: time.Hour, MaxRefresh: time.Hour,
Authenticator: JWTAuthenticator, Authenticator: JWTAuthenticator,
-11
View File
@@ -1,11 +0,0 @@
export interface Pong {
message: string;
}
export async function pingApi(): Promise<String> {
let result: String = ''
await fetch('http://localhost:8080/ping')
.then(response => response.json())
.then(jsonResponse => result = jsonResponse.message)
return result
}
+14 -6
View File
@@ -6,8 +6,18 @@ import { ref } from 'vue';
const email = ref('') const email = ref('')
const password = ref('') const password = ref('')
const baseURL = `http://${__APP_ENV__.APP_HOST_ADDRESS}:${__APP_ENV__.APP_API_PORT}`
function getArticles() { 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}` } headers: { "Authorization": `Bearer ${useAuthStore().token}` }
}) })
.then(response => response.json()) .then(response => response.json())
@@ -25,7 +35,7 @@ function jwtHandler(apiResponse: jwtFormat): void {
} }
function login(email: string, password: string): void { function login(email: string, password: string): void {
fetch(`http://localhost:${__APP_ENV__.API_PORT}/login/`, { fetch(`${baseURL}/login/`, {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
email: email, email: email,
@@ -54,10 +64,8 @@ function login(email: string, password: string): void {
<div> <div>
<div> <div>
<button @click="getArticles()">get all articles</button> <button class="button-primary" @click="getArticles()">get all articles</button>
<button @click="getArticles()">get all articles</button> <button class="button-primary" @click="ping()">ping</button>
<button @click="getArticles()">get all articles</button>
<button @click="getArticles()">get all articles</button>
</div> </div>
</div> </div>
</template> </template>
+1 -1
View File
@@ -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) //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 { 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", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
email: email, email: email,