Private repo: Test website #122949
Replies: 1 comment 2 replies
-
When accessing resources like data.txt from a JavaScript file hosted in a private repository, you'll encounter a CORS (Cross-Origin Resource Sharing) error due to security restrictions. To resolve this, you would need to set up CORS headers on your server to allow cross-origin requests. But, since you're trying to fetch data from a private GitHub repository, you can't directly access it from client-side due to some security restrictions. But I think you could proxy the request through a server that you control. You can find the source code for that online. Also make sure your GitHub token has all the necessary permissions to access the repository, that's something people sometimes overlook. Hope this helps in some way. |
Beta Was this translation helpful? Give feedback.
-
I have started a simple private repo, with an index.html which has a javascript that needs to fetch(data.txt).
After many many failed attempts, i managed to finally preview the website by clicking raw, which generates a temporary token, and then using
https://htmlpreview.github.io/?https://raw.githubusercontent.com/[USER]/[REPO]/main/index.html?token=[TOKEN]
But of course the script won't work, because it can't access data.txt.
Thus, I suppose I need a permanent token, to both look at the website and for the script to access data.txt with.
I tried to generate personal access tokens, first classic and now fine-grained, which should have read access to the content of the repo. However, using this token in the previous url results in "TypeError: Failed to fetch".
There must be a simple way to make this work?
I just cannot figure it out for the life of me.
Beta Was this translation helpful? Give feedback.
All reactions