when use GIN to provide cross origin rest api service, a specific situation you will encounter the problem of prefilght fail. mostly, it will look like : Access to fetch at ‘10.195.11.44:3001/connectBusiDb’ from origin ‘http://10.195.11.44:8080' has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: Redirect is not allowed for a preflight request. Or authentication relatived.
the way to go over this issue is to add the OPTIONS routing map yourself for the url. and I am hoping to have a configuration on gin to deal it, that we can save much time on add the redundant code.
TO-DO:
figure out why this gin framework doesn’t include solution inside.
try to make a pr to contribute.
REF: complain: github.com/gin-gonic/gin/issues/211 similar issue description: github.com/gin-gonic/gin/issues/2801 knowledge about gin middleware: pjchender.dev/golang/gin-middleware knowledge about CORS on front end:developer.aliyun.com/article/753657 knowledge about CORS-refferrer: web.dev/referrer-best-practices AND developers.google.com/web/updates/2020/07/r.. code of middleware to enable CORS for GIN:segmentfault.com/a/1190000024437309 AND segmentfault.com/a/1190000022781975