[Lazarus] SQLDBRestBridge

duilio foschi octopushole at gmail.com
Mon Nov 7 23:58:34 CET 2022


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.

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.

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];

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

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

Thank you

Peppe

project1.html:1 Access to XMLHttpRequest at
'http://localhost:3000/metadata/?fmt=json&humanreadable=0' from origin
'http://localhost:8000' has been blocked by CORS policy: Response to
preflight request doesn't pass access control check: No
'Access-Control-Allow-Origin' header is present on the requested
resource.
project1.js:263 Uncaught {fMessage: 'HTTP request error
@http://localhost:3000/metadata/?fmt=json&humanreadable=0'}
cb @ project1.js:263
error (async)
Execute$2 @ project1.js:12331
Execute @ project1.js:12316
btnClick @ project1.js:12649
cb @ project1.js:241
Click @ project1.js:6631
HandleDoClick @ project1.js:6120
cb @ project1.js:241
project1.js:12356          GET
http://localhost:3000/metadata/?fmt=json&humanreadable=0
net::ERR_FAILED
Execute$2 @ project1.js:12356
Execute @ project1.js:12316
btnClick @ project1.js:12649
cb @ project1.js:241
Click @ project1.js:6631
HandleDoClick @ project1.js:6120
cb @ project1.js:241

On Sun, Nov 6, 2022 at 11:27 PM Michael Van Canneyt via lazarus
<lazarus at lists.lazarus-ide.org> wrote:
>
>
>
> On Sun, 6 Nov 2022, duilio foschi wrote:
>
> > Hi Michael,
> >
> > I am digging into your SQLDBRestBridge component. Very useful code.
> >
> > I could fix and run both the server part and the client part (I used
> > the BufDataset client).
> >
> > My code (with very few changes applied to the original one) can be
> > downloaded from this link:
> > https://mega.nz/file/Gxx3FBya#LbvDvuFnH5rUDVAdPoGyuUCnkNE761A62SZ1MYX8oFQ
> >
> > I hope it be helpful for somebody.
> >
> >
> >
> > I have 2 questions:
> >
> > 1. the client needs to know the name of the primary key (PK) of each
> > table. Is there a way to ask the server for the name of the PK of
> > table A?  Or to have the PK listed in the metadata?
>
> Normally the server has this info, and the primary key is retrieved when
> exposing a database. It is part of fieldinfo, but not yet exposed in the
> metadata, I think. I will add it, this is easy to do.
>
> > 2. the client needs to periodically refresh the visible rows in the
> > event that another client applied changes to the DB. How is this done?
> > I reckon that the client will remember the last command
> > like
> > BASEURL/resourcename?limit=10&Offset=50
> > and reissue it. Right?
>
> Yes, but you need to program this yourself.
>
> Michael.
> --
> _______________________________________________
> lazarus mailing list
> lazarus at lists.lazarus-ide.org
> https://lists.lazarus-ide.org/listinfo/lazarus


More information about the lazarus mailing list