[Lazarus] SQLDBRestBridge

Michael Van Canneyt michael at freepascal.org
Tue Nov 8 07:56:08 CET 2022



On Mon, 7 Nov 2022, duilio foschi wrote:

> I fixed the code in Lazarus and got a client based on BufDataClient
> that successfully talks with a restbridge server.
>
> As a next step, I'd like to connect to the same server from a TWebForm
> of TMS Web Core library.

Normally, TMS Web Core contains a dataset component that handles SQLDBRest
connections?.

I wrote it myself for them.

>
> I started with a slow step. There is only a TWebHttpRequest in the
> form (which has the same functions of a TFPHTTPClient) and it issues a
> GET to URL
> http://localhost:3000/metadata/?fmt=json&humanreadable=0
>
> This command works ok in the windows client.
>
> Here, I get the errors shown in pic
> https://i.ibb.co/dpsjfQQ/1.jpg
>
> The message (a CORS error) is attached below.

Aaaahhh... Welcome to CORS hell... :/

>
> Weird enough, the message is there even after changing the server code
> in this way:
>
> original code:
>   FDisp.DispatchOptions:=FDisp.DispatchOptions+[rdoCustomView,rdoHandleCORS];
>
> new code
>    FDisp.DispatchOptions:=FDisp.DispatchOptions+[rdoCustomView];

This is the exact opposite of what you should do.

The rdoHandleCORS option must be there, or CORS will not be handled at all.

>
> Is there a way to tell the server to ignore CORS errors?
>

The CORS errors are from the browser, not from the server.


> Or there a way to sweet-talk the server to accept the requests from a
> TMS Web form? :)

Yes, you must add localhost as an allowed origin in CORSAllowedOrigins.

FDisp.CORSAllowedOrigins:='localhost:3000'

If you are not using authentication, as an alternative, you can try
FDisp.CORSAllowedOrigins:='*'

Michael.


More information about the lazarus mailing list