Fix up accessing ui in dev mode via env variables

This commit is contained in:
Amarpreet Minhas 2020-01-22 22:45:07 -05:00
parent 38bd348737
commit 4208190c9a
3 changed files with 8 additions and 5 deletions

View file

@ -54,7 +54,7 @@ func main() {
func Routes() *chi.Mux { func Routes() *chi.Mux {
router := chi.NewRouter() router := chi.NewRouter()
cors := cors.New(cors.Options{ 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"}, AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"},
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"}, AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"},
AllowCredentials: true, AllowCredentials: true,

View file

@ -260,9 +260,9 @@ func refresh(w http.ResponseWriter, r *http.Request) {
func setCookies(w http.ResponseWriter, jwt string, expiration time.Time) { func setCookies(w http.ResponseWriter, jwt string, expiration time.Time) {
splitToken := strings.Split(jwt, ".") 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) 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) http.SetCookie(w, &signatureCookie)
return 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) { func sendEmailToken(w http.ResponseWriter, token string, name string, email string) (returnMessage ReturnMessage, ok bool) {
header := "Thanks for joining sudoscientist, " + name + "!" header := "Thanks for joining sudoscientist, " + name + "!"
body := "\n\nPlease click the following link to verify your email: " 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} email_array := [1]string{email}
composed_email := ComposedEmail{ composed_email := ComposedEmail{
To: email_array, To: email_array,

View file

@ -3,4 +3,7 @@ export EMAIL_SECRET="CHANGEMEALSOPLS"
export JWT_SECRET="CHANGEMEALSO" export JWT_SECRET="CHANGEMEALSO"
export POSTAL_API="https://POSTAL_URL" export POSTAL_API="https://POSTAL_URL"
export POSTAL_SRC_EMAIL="postal-source@domain.com" 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://"