Shopify代理URL不起作用,但没有解决
我的Shopify应用程序代理信息:
Subpath prefix: apps
Subpath: rma
Host: https://www.example.com/shopdevc/shopifyAPI/
如果我直接使用 https://www.example 。
但是,在我的React函数中,查询“/apps/rma”返回的返回,
<!DOCTYPE html> <html lang="en"> <head> <script type="module" src="/@vite/client"></script> <script type="module"> import RefreshRuntime from "/@react-refresh" RefreshRuntime.injectIntoGlobalHook(window) window.$RefreshReg$ = () => {} window.$RefreshSig$ = () => (type) => type window.__vite_plugin_react_preamble_installed__ = true </script> <meta charset="UTF-8" /> </head> <body> <div id="app"><!--app-html--></div> <script type="module" src="/src/entry-client.jsx"></script> </body> </html>
我的代理URL或路径有问题吗?我的文件夹结构是
"c:\wwwroot\shopDevC\shopifyAPI\apps\rma\index.aspx"
index.aspx是默认文档。
我的代码:
function delayed_render(async_fun, deps=[]) {
const [output, setOutput] = useState();
useEffect(async () => setOutput(await async_fun()), deps);
return (output === undefined) ? null : output;
}
function TestAPI() {
return delayed_render(async () => {
// const resp = await fetch(`https://www.example.com/shopdevc/shopifyAPI/apps/rma`); // this works fine
const resp = await fetch(`/apps/rma`); //this does not work even though our proxy is set to https://www.example.com/shopdevc/shopifyAPI
const data = await resp.text();
return <div>
<h1> Fetch data from an api in react: {data} </h1>
</div>;
My shopify app proxy information:
Subpath prefix: apps
Subpath: rma
Host: https://www.example.com/shopdevc/shopifyAPI/
If I query the host directly using https://www.example.com/shopdevc/shopifyAPI/apps/rma, it works great.
But, in my React function, querying "/apps/rma" returns
<!DOCTYPE html> <html lang="en"> <head> <script type="module" src="/@vite/client"></script> <script type="module"> import RefreshRuntime from "/@react-refresh" RefreshRuntime.injectIntoGlobalHook(window) window.$RefreshReg$ = () => {} window.$RefreshSig$ = () => (type) => type window.__vite_plugin_react_preamble_installed__ = true </script> <meta charset="UTF-8" /> </head> <body> <div id="app"><!--app-html--></div> <script type="module" src="/src/entry-client.jsx"></script> </body> </html>
Is there something wrong with my proxy url or path? My folder structure is
"c:\wwwroot\shopDevC\shopifyAPI\apps\rma\index.aspx"
where index.aspx is the default document.
My code:
function delayed_render(async_fun, deps=[]) {
const [output, setOutput] = useState();
useEffect(async () => setOutput(await async_fun()), deps);
return (output === undefined) ? null : output;
}
function TestAPI() {
return delayed_render(async () => {
// const resp = await fetch(`https://www.example.com/shopdevc/shopifyAPI/apps/rma`); // this works fine
const resp = await fetch(`/apps/rma`); //this does not work even though our proxy is set to https://www.example.com/shopdevc/shopifyAPI
const data = await resp.text();
return <div>
<h1> Fetch data from an api in react: {data} </h1>
</div>;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我只是使用Shopify代理绕过,并在index.js中滚动:
I simply bypassed using the shopify proxy and rolled my own in index.js:
我今天也一直在研究类似的问题。几乎我的确切搜索短语
Shopify代理URL无法正常工作,但无需工作
。这不是解决您问题的答案,但可能会帮助您,也许其他人可能会觉得这有用。我认为这是URL分辨率,而不是您的React代码。我的骨架是用
shopify-cli
构建的:shopify create create app node
。加载
https:// {shop} .myshopify.com/{proxy_prefix}/{proxy_path}/{剩余path}
,我在浏览器开发人员窗口中看到了什么。根。src =“/src/entrc/entry-client.jsx”
等。 。我的解决方案是将root替换为服务器文件server/index.js
,。以下为DIST(isprod === true
)中编译的文件的工作:对于开发服务器(
!isprod
e节),需要进行更多替换:然后允许字符串替换
vite.Createserver
实例需要具有MiddleWareMode:“ SSR”
(服务器端渲染),这意味着未注入react-ref-refresh
代码。因此,我将其包含在最终注释中 - 我仍在尝试弄清楚如何使套接字
__ vite_ping
转到我的host
。祝你好运。 ngāmihinui。
I too have been working on a similar problem today. Almost my exact search phrase
Shopify proxy url not working but unproxied is working
. This is not an answer to your problem but may help you and perhaps others may find this useful. It's the url resolution I think, not your react code.My skeleton was built with the
shopify-cli
:shopify create app node
.What I saw in my browser developer window when loading
https://{shop}.myshopify.com/{proxy_prefix}/{proxy_path}/{rest-of-path}
was that assets were requested to the root.src="/src/entry-client.jsx"
etc. Which was trying to loadhttps://{shop}.myshopify.com/src/entry-client
. My solution was to replace the root with the full url of my host in the server fileserver/index.js
, . The following works for the compiled files in dist (isProd === true
):For the development server (the
!isProd
section) more substitutions are required:And then to allow the string substitutions the
vite.createServer
instance needs to havemiddlewareMode: "ssr"
(Server-Side Rendering) which meant that thereact-refresh
code was not injected. So I included this:On a final note - I'm still trying to figure out how to make the socket
__vite_ping
go to myHOST
.Good luck. Ngā mihi nui.