Shopify / shopify-app-bridge

https://shopify.dev/docs/api/app-bridge
86 stars 9 forks source link

disable "fetch" feature in Remix Example App #256

Closed mgill404 closed 9 months ago

mgill404 commented 10 months ago

I'm trying to disable fetch in my project, which I started with shopify/app

The Resource Fetching documentation alludes to this being possible. I am trying to do this as I am trying to make authenticated calls to AWS, and I need my own Auth header for this.

I have found some hints about how to do this, but can't put the pieces together.

In #239 I found an example, so I tried adding the meta tag to root.jsx

export default function App() {
  return (
    <html>
      <head>
        <meta charSet="utf-8" />
        <meta name="viewport" content="width=device-width,initial-scale=1" />
        <meta name="shopify-disabled-features" content="fetch" />

I've also tried the other approach in #239 by setting the shopify object in entry.client.js I believe this is not happening early enough, but I don't know how to make it happen earlier than this.

if (typeof window !== "undefined") {
  window.shopify = {
    config: {
      disabledFeatures: ["fetch"],
    },
  };
}

Neither of these approaches have fixed my issues. I continue to see in the Network Developer Chrome tool that fetch calls are routed through app-bridge.js

To Reproduce

Steps to reproduce the behaviour:

1. npm init @shopify/app@latest
2. make the code changes above
3,. make a fetch call.

If applicable, add screenshots to help explain your problem.

app-bridge-initiator

Expected behaviour

I would expect to use the default fetch API available in the browser. The actual behavior is that I'm using a fetch API provided by App Bridge.

Contextual information

The fetch call is being made to access a lambda on AWS. I am using client-lambda which makes the fetch.

Packages and versions

These are all the shopify packages listed in package-lock.json

"@shopify/app": "3.50.2", "@shopify/app-bridge-types": "^0.0.3", "@shopify/cli": "3.50.2", "@shopify/polaris": "^12.0.0", "@shopify/shopify-api": "^8.0.2", "@shopify/shopify-app-remix": "^2.1.0", "@shopify/shopify-app-session-storage-prisma": "^2.0.0",

Platform

mgill404 commented 10 months ago

To add some additional context, I think I don't always want the bridge fetch behavior to be removed. It is helpful when routing within my application as I will need to authenticate the requests.

I would like to be able to opt-out of it in the circumstance that I'm connecting to AWS. I'm scared this isn't possible.

mgill404 commented 9 months ago

I decided to just make the call on the server side.