admin管理员组

文章数量:1292350

I am trying to call app proxy but getting error in dev tools -> Network Response body is not available to scripts (Reason: CORS Failed)

I have already tried setting my header as * as well as headers: { "Content-Type": "application/json", 'Access-Control-Allow-Origin': https://${storeDomain}.myshopify, } url in my fetch is https://${storeDomain}/apps/my-subpath and proxy url in app proxy is cloudflare tunnel with api/myfile.jsx ( which is accesible from my browser to ensure it is running)

Any idea what am I missing

I have already tried setting my header as * as well as headers: { "Content-Type": "application/json", 'Access-Control-Allow-Origin': https://${storeDomain}.myshopify, }

I am trying to call app proxy but getting error in dev tools -> Network Response body is not available to scripts (Reason: CORS Failed)

I have already tried setting my header as * as well as headers: { "Content-Type": "application/json", 'Access-Control-Allow-Origin': https://${storeDomain}.myshopify, } url in my fetch is https://${storeDomain}/apps/my-subpath and proxy url in app proxy is cloudflare tunnel with api/myfile.jsx ( which is accesible from my browser to ensure it is running)

Any idea what am I missing

I have already tried setting my header as * as well as headers: { "Content-Type": "application/json", 'Access-Control-Allow-Origin': https://${storeDomain}.myshopify, }

Share Improve this question asked Feb 13 at 8:43 NavdeepNavdeep 11 bronze badge 1
  • Please provide enough code so others can better understand or reproduce the problem. – Community Bot Commented Feb 13 at 8:48
Add a comment  | 

1 Answer 1

Reset to default 0

Solution for the CORS issue in your Shopify App Proxy:

  1. On your backend (API) server, add these CORS headers:

    app.use((req, res, next) => { res.header('Access-Control-Allow-Origin', '*'); res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS'); res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization'); if (req.method === 'OPTIONS') { return res.status(200).end(); } next(); });

  2. In your frontend fetch request, remove the Access-Control-Allow-Origin header (it should only be set server-side):

    fetch(https://${storeDomain}/apps/my-subpath, { method: 'GET', credentials: 'include', headers: { 'Content-Type': 'application/json' } })

本文标签: Getting error CORS failed in my Shopify App ProxyStack Overflow