From 08e1a02600a40ea9b157bb56ca559c7c807a1d2a Mon Sep 17 00:00:00 2001 From: Victor Cornille Date: Fri, 15 Nov 2024 21:31:59 +0100 Subject: [PATCH] ~ | Rdy for prod --- goserv/app/api/post.go | 32 +++++++++++++++------- goserv/app/templates/pages/dashboard.js | 8 +++--- goserv/app/templates/pages/login_page.tmpl | 2 +- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/goserv/app/api/post.go b/goserv/app/api/post.go index 98d5514..87c58ec 100644 --- a/goserv/app/api/post.go +++ b/goserv/app/api/post.go @@ -3,6 +3,14 @@ package api import ( "time" "net/http" + "fmt" + "database/sql" + "crypto/rand" + "encoding/base64" + "encoding/json" + "log" + "os" + "github.com/gin-gonic/gin" "github.com/BolvicBolvicovic/bluebeam/templates/components" "github.com/BolvicBolvicovic/bluebeam/database" @@ -10,13 +18,7 @@ import ( "github.com/BolvicBolvicovic/bluebeam/criterias" "google.golang.org/api/sheets/v4" "google.golang.org/api/drive/v3" - "fmt" - "database/sql" - "crypto/rand" "golang.org/x/crypto/bcrypt" - "encoding/base64" - "encoding/json" - "log" ) func ClearSessionKey(username string, c *gin.Context) error { @@ -29,8 +31,13 @@ SET WHERE username = ?; ` - c.SetCookie("bluebeam_username", "", -1, "/", "localhost", true, true) - c.SetCookie("bluebeam_session_key", "", -1, "/", "localhost", true, true) + if os.Getenv("MODE") == "dev" { + c.SetCookie("bluebeam_username", "", -1, "/", "localhost", true, true) + c.SetCookie("bluebeam_session_key", "", -1, "/", "localhost", true, true) + } else { + c.SetCookie("bluebeam_username", "", -1, "/", "bluebeam.dev", true, true) + c.SetCookie("bluebeam_session_key", "", -1, "/", "bluebeam.dev", true, true) + } _, err := database.Db.Exec(query, username) return err } @@ -393,8 +400,13 @@ WHERE c.JSON(http.StatusInternalServerError, gin.H{"error": "Error updating key session"}) return } - c.SetCookie("bluebeam_username", user.Username, 86400, "/", "localhost", true, true) - c.SetCookie("bluebeam_session_key", strkey, 86400, "/", "localhost", true, true) + if os.Getenv("MODE") == "dev" { + c.SetCookie("bluebeam_username", user.Username, 86400, "/", "localhost", true, true) + c.SetCookie("bluebeam_session_key", strkey, 86400, "/", "localhost", true, true) + } else { + c.SetCookie("bluebeam_username", user.Username, 86400, "/", "bluebeam.dev", true, true) + c.SetCookie("bluebeam_session_key", strkey, 86400, "/", "bluebeam.dev", true, true) + } c.JSON(http.StatusAccepted, gin.H{"message": "connected!"}) } } diff --git a/goserv/app/templates/pages/dashboard.js b/goserv/app/templates/pages/dashboard.js index 746e14d..426fc38 100644 --- a/goserv/app/templates/pages/dashboard.js +++ b/goserv/app/templates/pages/dashboard.js @@ -258,7 +258,7 @@ function sendCriterias(event) { reader.onload = function() { const features = JSON.parse(reader.result); - fetch('https://localhost/criterias', { + fetch('/criterias', { method: 'POST', mode: 'cors', headers: { 'Content-Type': 'application/json' }, @@ -302,7 +302,7 @@ function updateEmail(event) { const email = document.getElementById("email").value; const emailStatus = document.getElementById("emailStatus"); - fetch('https://localhost/updateEmail', { + fetch('/updateEmail', { method: 'PATCH', mode: 'cors', headers: { 'Content-Type': 'application/json' }, @@ -335,7 +335,7 @@ function updateAPIKey(event) { const apiKey = document.getElementById("apiKey").value; const apiKeyStatus = document.getElementById("apiKeyStatus"); const api = apiKey.indexOf("-") == -1 ? "gemini" : "openai"; - fetch('https://localhost/updateAPIKey', { + fetch('/updateAPIKey', { method: 'PATCH', mode: 'cors', headers: { 'Content-Type': 'application/json' }, @@ -478,7 +478,7 @@ async function pickerCallback(data) { return obj; }); - fetch('https://localhost/criterias', { + fetch('/criterias', { method: 'POST', mode: 'cors', headers: { 'Content-Type': 'application/json' }, diff --git a/goserv/app/templates/pages/login_page.tmpl b/goserv/app/templates/pages/login_page.tmpl index a077d76..cc1e664 100644 --- a/goserv/app/templates/pages/login_page.tmpl +++ b/goserv/app/templates/pages/login_page.tmpl @@ -85,7 +85,7 @@ if (data.error) { messageOutput.innerHTML = data.error; } else { - window.location.href = "https://localhost"; + window.location.href = "/"; } }) .catch(error => {