From 4208190c9a1aeb42630643277b2b2005bc34d2ec Mon Sep 17 00:00:00 2001 From: Asara Date: Wed, 22 Jan 2020 22:45:07 -0500 Subject: [PATCH] Fix up accessing ui in dev mode via env variables --- main.go | 2 +- packages/auth/auth.go | 6 +++--- settings/website.env-sample | 5 ++++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 9f6d7b8..ad3a8d9 100644 --- a/main.go +++ b/main.go @@ -54,7 +54,7 @@ func main() { func Routes() *chi.Mux { router := chi.NewRouter() cors := cors.New(cors.Options{ - AllowedOrigins: []string{"https://sudoscientist.com", "https://www.sudoscientist.com"}, + AllowedOrigins: []string{os.Getenv("UI_PROTO") + os.Getenv("UI_ADDR") + os.Getenv("UI_PORT"), os.Getenv("UI_PROTO") + "www." + os.Getenv("UI_ADDR") + os.Getenv("UI_PORT")}, AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"}, AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"}, AllowCredentials: true, diff --git a/packages/auth/auth.go b/packages/auth/auth.go index cf7763f..b722d96 100644 --- a/packages/auth/auth.go +++ b/packages/auth/auth.go @@ -260,9 +260,9 @@ func refresh(w http.ResponseWriter, r *http.Request) { func setCookies(w http.ResponseWriter, jwt string, expiration time.Time) { splitToken := strings.Split(jwt, ".") - dataCookie := http.Cookie{Name: "DataCookie", Value: strings.Join(splitToken[:2], "."), Expires: expiration, HttpOnly: false, Path: "/", Domain: ".sudoscientist.com", MaxAge: 360, Secure: true} + dataCookie := http.Cookie{Name: "DataCookie", Value: strings.Join(splitToken[:2], "."), Expires: expiration, HttpOnly: false, Path: "/", Domain: os.Getenv("UI_ADDR"), MaxAge: 360} http.SetCookie(w, &dataCookie) - signatureCookie := http.Cookie{Name: "SignatureCookie", Value: splitToken[2], Expires: expiration, HttpOnly: true, Path: "/", Domain: ".sudoscientist.com", MaxAge: 360, Secure: true} + signatureCookie := http.Cookie{Name: "SignatureCookie", Value: splitToken[2], Expires: expiration, HttpOnly: true, Path: "/", Domain: os.Getenv("UI_ADDR"), MaxAge: 360} http.SetCookie(w, &signatureCookie) return } @@ -270,7 +270,7 @@ func setCookies(w http.ResponseWriter, jwt string, expiration time.Time) { func sendEmailToken(w http.ResponseWriter, token string, name string, email string) (returnMessage ReturnMessage, ok bool) { header := "Thanks for joining sudoscientist, " + name + "!" body := "\n\nPlease click the following link to verify your email: " - link := os.Getenv("WEB_ADDR") + "/v1/api/auth/verify/" + token + link := os.Getenv("API_ADDR") + "/v1/api/auth/verify/" + token email_array := [1]string{email} composed_email := ComposedEmail{ To: email_array, diff --git a/settings/website.env-sample b/settings/website.env-sample index 207f180..0f426e0 100644 --- a/settings/website.env-sample +++ b/settings/website.env-sample @@ -3,4 +3,7 @@ export EMAIL_SECRET="CHANGEMEALSOPLS" export JWT_SECRET="CHANGEMEALSO" export POSTAL_API="https://POSTAL_URL" export POSTAL_SRC_EMAIL="postal-source@domain.com" -export WEB_ADDR="https://apidomain.tld" +export API_ADDR="https://apidomain.tld" +export UI_ADDR="sudosci.ui" +export UI_PORT=":3000" +export UI_PROTO="http://"