HTML5 URL'S AGAIN

Bringing your stacks to the web

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

HTML5 URL'S AGAIN

Post by adventuresofgreg » Wed Jul 19, 2023 3:48 pm

I'm back developing an html5 app and have just RE-LEARNED that you cannot "put URL https://..." if the URL is not hosted on the same server as your html5 app. I'm using a bunch of API's in this web app, like a AI api from openai, a non-psuedo random number generator api from another web site, and a few different photo api's. How is one supposed to dev using the amazing power of api's if you can't post or get data back from them because they aren't hosted on your own server??

Does anyone have any work-arounds?

Thanks,
Greg

adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

Re: HTML5 URL'S AGAIN

Post by adventuresofgreg » Wed Jul 19, 2023 10:41 pm

I'm executing the cURL for one particular api as a shell command. Maybe shell commands don't work on web deployment? like: put shell("curl -s "https??api.replicate.....etc")

Thomas seewald
Posts: 7
Joined: Mon Sep 26, 2016 12:06 pm

Re: HTML5 URL'S AGAIN

Post by Thomas seewald » Thu Aug 03, 2023 9:06 am

If you can host an app on a server, then you can - I think - also run the free server version of Livecode there.
I ask for database queries, for example, whether the app - platform is "web". If yes I send a post to the url with "sqlquery=thequery" and let the server do the query. I send the result back as a response.


Server-Side for example

<?lc
put the keys of $_POST into tKeys
put the keys of $_GET into tKeysGet

if tKeys is not empty then
put urldecode($_POST["sqlquery"]) into sqlquery

else
put urldecode($_GET["sqlquery"]) into sqlquery

end if

put revopendatabase("mysql","localhost","database","user","Password") into connid
put revDataFromQuery(,, connid, SQLQuery ) into schonda


put schonda

revclosedatabase connid
?>

Nikovash
Posts: 14
Joined: Thu Mar 24, 2011 7:38 am

Re: HTML5 URL'S AGAIN

Post by Nikovash » Sun Sep 10, 2023 11:50 pm

so the reason this doesn't work if you read the error on the web browser console is its a CORS violation, and currently Livecode is using a soon to be deprecated method for URL treatments

IF you add a CORS proxy to a global on preOpenStack (either a public one or create your own) you can then do something like

put gTHeCORSProxyURL & "http://www.thewebsiteyouwant.com" into tURL

put URL tURL should now work

so in my code that i use it would look something like this:

global gCorsProxy

on preOpenStack
put "https://corsproxy.io/?" into gCorsProxy
end preOpenStack

--later in code

on doSomething
put gCorsProxy into tRequest
put "https://coincodex.com/api/coincodex/get ... anges/YERB" after tRequest
put URL tRequest into tResult
--then do whatever you need with tResult in this example you get JSON formatted data about a cryptocurrency named Yerbas a CORS Proxy will work around same domain origin problems until such a time Livecode deals with requests in a different manner and would ultimately work.
end doSomething

WARNING!!! A CORS Proxy server can man-in-the-middle-data so be carful about what data you are sending and who the server belongs to, and if it may compromise user data. In my example I don't care because its pulling publicly available data and not passing user or customer data if this is a concern I would look at building your own CORS Proxy server as then you know with absolute confidence who is using that data and how

Post Reply

Return to “HTML5”