15 AnswersNew Answer
I want to create an application which interacts with a local file which acts as a database of JSON object. I followed Stackoverflow : https://code.sololearn.com/WjcNo9zLK55l/?ref=app But it logs error message: Access to XMLHttpRequest at 'file:///C:/Users/Gordon/Desktop/testing.txt' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https. How to solve this? But if I set some low protection level, means malicious attempt from Internet also allowed?
3/25/2019 4:41:55 AMGordon
15 AnswersNew Answer
Run local server to access the web file. If you do not have local server installed. Use cmd prompt to run npm install http-server -g to install a local server (You need to have nodejs installed) Then run http-server -p8000 from your working folder. Open browser with address http://localhost:8000
Gordon you have to use http protocol instead of file protocol. Also you can try to include crossorigin ="anonymous"
Gordon i don't think so :) -http protocol == web hosting or you can host it on your local machine using xampp -file transfer protocol == your local computer that runs your index.html file => here cors won't let you continue
r8w9 oh i see, thanks
//You can use this API, it enables cross-origin requests to anywhere. https://cors-anywhere.herokuapp.com ://Deom https://github.com/Rob--W/cors-anywhere
🤔 But I want to process sensitive information of my company, and so I don't want the data to be uploaded to somewhere. Is there any way?
Sololearn playground is running from codes.sololearn domain, so you have cors issue. If you create local html/js file, it should be working fine.
Dy defualt, your windows blocks the web access from outside, unless you configure it to allow your ip to expose to web through port 80
You always can check from your current ip address. https://www.whatismyip.com By opening the address from browser.
Coder understand, current trend is to print logs in html
Calviղ but it prompts this error when I am running the file locally.
Do you have locals server?
Calviղ if I configure this way, means someone outside can also access these files on my computer? 🤔
r8w9 oh i can use http protocol to access local files?
Sololearn Inc.535 Mission Street, Suite 1591
Send us a message