Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting multiple cookies #204

Open
michaelCaleyWhaley opened this issue Aug 28, 2024 · 0 comments
Open

Setting multiple cookies #204

michaelCaleyWhaley opened this issue Aug 28, 2024 · 0 comments

Comments

@michaelCaleyWhaley
Copy link

Trying to set multiple cookies is resulting in only one cookie being returned via api gateway. Is there a specific method I am supposed to use other than c.SetCookie?

package main

import (
	"context"
	"log"
	"net/http"
	"os"
	"utilitor/controllers/code"
	"utilitor/controllers/contacts"
	"utilitor/initialisers"
	"utilitor/middleware"

	"github.com/aws/aws-lambda-go/events"
	"github.com/aws/aws-lambda-go/lambda"
	ginadapter "github.com/awslabs/aws-lambda-go-api-proxy/gin"
	"github.com/gin-gonic/gin"
)

var ginLambda *ginadapter.GinLambda
var isLocal = os.Args[len(os.Args)-1] == "--local"

func routes(r *gin.Engine) {
	r.Use(middleware.CrossOrigin)
	r.POST("/api/code", code.Controller)
	r.GET("/api/contact/list", middleware.VerifyAccessToken, contacts.Controller)

	r.GET("/api/test", func(c *gin.Context) {
		// origin := c.Request.Header.Get("Origin")
		// host := c.Request.Header.Get("Host")
		// reqHost := c.Request.Host

		domain := initialisers.GetConfig().CookieDomain
		c.SetCookie("test1", "test", 86400, "/", domain, true, true)
		c.SetCookie("test2", "test", 86400, "/", domain, true, true)

		c.JSON(http.StatusOK, gin.H{
			"cookies": []string{"cookie1", "cookie2"},
		})
	})
}

func init() {
	initialisers.LoadEnvVars()
	log.Printf("Gin cold start")
	r := gin.Default()
	routes(r)

	if isLocal {
		r.Run("localhost:4000")
		return
	}
	ginLambda = ginadapter.New(r)
}

func Handler(ctx context.Context, req events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
	return ginLambda.ProxyWithContext(ctx, req)
}

func main() {
	if isLocal {
		return
	}
	lambda.Start(Handler)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant