I have a script-min.js file in my Next.js app,, which does some data fetching from appwrite and renders some element with that. That script is hosted on: somthing.vercel.app/script-min.js
Here is the fetch function in that:
const t = await fetch(
`https://cloud.appwrite.io/v1/databases/*****/collections/*****/documents?queries[0]=equal("user_id", ["${this.userCode}"])&queries[1]=equal("is_active", [true])`,
{
method: "GET",
headers: {
"X-Appwrite-Project": "*******",
"Content-Type": "application/json",
},
}
);
For my use case, I want to add two script that will allow rendering some dom element in any website from any origin. If my add the following script in a app which is running on my localhost:**** it works perfectly,
<script src="https://something.vercel.app/script-min.js"></script>
<script>
Popwola.init("***********");
</script>
(note: script-min.js have Popwola class) but it doesn't work if I add that script in a html file and double click to open it, it doesn't fetch and logs the error in the screenshot.
What can I do if I want to allow access from any origin?
Have you added your something.vercel.app as a web platform in the console?
yes,, I've added this:
In your attached photo it seems like you're running it from a local html file?
?
yes, it is
Mmm, So then no host can be send like that, and it will better to use some server to access this file thorugh a server.
it works perfectly if I run it on loachost:port ,,
have to check if it works in like github pages/netlify etc..
let me check
Yes, as localhost:port is a server and any request from localhost set as the host are okay.
And if you're uploading it to something like github pages/netlify - static host. Then make sure to add a web platform with your full static host domain.
ummm,, I checked,, it only works on *.vercel.app,, but for my use case I want to allow from any origin, what can I do for that?
can I just add a * in my console for hostname?
Yes
It worked. Thanks!
<:appwriteupvote:899677724615016528>
[Solved]: Problem with Access-Control-Allow-Origin
Hey @niaz you exposed your .env file why?? https://github.com/NiazMorshed2007/popwola/blob/master/.env
Recommended threads
- Usage of the new Client() and dealing wi...
Hey guys, just a quick one - we had some web traffic the other day and it ended up bombing out - To put in perspective of how the app works, we have a Nuxt Ap...
- Cloud function deploy stucks in processi...
Been trying for the last hours to deploy my function but for whatever reason, alwasy stuck on processing!
- One-time Cloud migration blocked by data...
Hi, I’m blocked on a one-time migration from Appwrite Cloud to my self-hosted Appwrite instance. We already fixed the region issue, and the migration now corre...