ç°¡åãªã®ã§ããèªåç¨ã®ã¡ã¢ã¨ãã¦æ®ãã¾ã
reactããFiberã®APPãµã¼ãã¼ã«ã¢ã¯ã»ã¹ãããCORSã¨ã©ã¼ãã§ãã
CORSã¨ã©ã¼ã¨ã¯
ãã£ããããã¨ç°ãªããµã¤ãéã§ãã¼ã¿ãããåãããæã®ã¨ã©ã¼ã§ãã
èªåã®ä¾ã ã¨reactã¨fiberã§ããåããµã¼ãã¼ã«ãã£ã¦ãéããµã¤ãæ±ãã§ãã
詳細ã¯ä»¥ä¸ã®ãµã¤ããã¿ã¦ãã ãã
https://developer.mozilla.org/ja/docs/Web/HTTP/CORS/Errors
https://zenn.dev/yarai/articles/6e3c5b017a5b8d
fiberã§ã®CORS対å¿
package main import ( "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/middleware/cors" ) func main() { app := fiber.New() app.Use(cors.New(cors.Config{ AllowOrigins: "http://localhost:5173", AllowMethods: "GET, POST, PUT, DELETE", AllowHeaders: "Origin, Content-Type, Accept", })) app.Get("/", func(c *fiber.Ctx) error { return c.SendString("Hello, World!") }) app.Listen(":3000") }
è£è¶³
app.Use()ã¡ã½ããã使ç¨ãã¦CORSï¼Cross-Origin Resource Sharingï¼
ããã«ã¦ã§ã¢ãã¢ããªã±ã¼ã·ã§ã³ã«è¿½å ãã¾ãããã®ããã«ã¦ã§ã¢ã¯ã
ç°ãªããªãªã¸ã³ããã®ãªã¯ã¨ã¹ãã許å¯ããããã«ä½¿ç¨ããã¾ãã
ããã§ã¯ãcors.New()é¢æ°ã«CORSè¨å®ã渡ãã¦ãã¾ãã
è¨å®ã«ã¯ãAllowOriginsã§è¨±å¯ãããªãªã¸ã³ï¼ãã®å ´åã¯http://localhost:5173ï¼ã
AllowMethodsã§è¨±å¯ããHTTPã¡ã½ããï¼GET, POST, PUT, DELETEï¼ã
ããã¦AllowHeadersã§è¨±å¯ããHTTPãããã¼ï¼Origin, Content-Type, Acceptï¼ãæå®ãã¦ãã¾ãã