Re: [Lazarus] SQLDBRestBridge

2022-11-07 Thread duilio foschi via lazarus
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
 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@lists.lazarus-ide.org
> https://lists.lazarus-ide.org/listinfo/lazarus
-- 
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] GStreamer API unit added

2022-11-07 Thread Aruna Hewapathirane via lazarus
Hi Michael,

Many thanks for the link. I have a few more questions please? I am running
FPC 3.2.0
and Lazarus 2.0.10 how do I get your gstreamer code into my installation?
What is the
preferred or best way to do this? It is my first time so apologies if this
is a silly question.

Many thanks once again for your help.

Aruna

On Mon, Nov 7, 2022 at 2:14 AM Michael Van Canneyt via lazarus <
lazarus@lists.lazarus-ide.org> wrote:

>
> Hello,
>
> Yes, see here:
>
> https://gitlab.com/freepascal.org/fpc/source/-/tree/main/packages/gstreamer
>
> Michael.
>
> On Sun, 6 Nov 2022, Aruna Hewapathirane wrote:
>
> > Hello Michael,
> >
> > I would be very interested in this. Is there a link to the source and the
> > example code please?
> >
> > Thanks - Aruna
> >
> > On Tue, Nov 1, 2022 at 6:45 AM Michael Van Canneyt via lazarus <
> > lazarus@lists.lazarus-ide.org> wrote:
> >
> >>
> >> Hello,
> >>
> >> For all people interested in sound/video streaming:
> >>
> >> After lots of work, I added the gst unit to the FPC packages.
> >> This unit contains the import declarations for the full libgstreamer-1.0
> >> API.
> >> I didn't translate all C macros, but if you need some which I didn't
> >> translate, let me know and I will add them.
> >>
> >> For those that are not in the know:
> >> gstreamer is a powerful audio/video stream system, used on most modern
> >> linux
> >> distributions (it may be available on mac/windows, but I didn't test
> >> those).
> >>
> >> I have also added a simple demo, that shows how to play a mp3 file.
> >>
> >> I'm not an expert in sound/video streams, so if someone can contribute a
> >> more elaborate example, it would be most welcome :)
> >>
> >> Enjoy,
> >>
> >> Michael.
> >> --
> >> ___
> >> lazarus mailing list
> >> lazarus@lists.lazarus-ide.org
> >> https://lists.lazarus-ide.org/listinfo/lazarus
> >>
> >
> --
> ___
> lazarus mailing list
> lazarus@lists.lazarus-ide.org
> https://lists.lazarus-ide.org/listinfo/lazarus
>
-- 
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] SQLDBRestBridge

2022-11-07 Thread Michael Van Canneyt via lazarus




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.
--
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus


Re: [Lazarus] GStreamer API unit added

2022-11-07 Thread Michael Van Canneyt via lazarus




On Mon, 7 Nov 2022, Aruna Hewapathirane wrote:


Hi Michael,

Many thanks for the link. I have a few more questions please? I am running
FPC 3.2.0
and Lazarus 2.0.10 how do I get your gstreamer code into my installation?
What is the
preferred or best way to do this? It is my first time so apologies if this
is a silly question.


In your case, I would recommend simply to copy the units into your project
folder.

Alternatively, copy them to some folder on your harddisk, and add this
folder to the unit path in the "project options" dialog in Lazarus. 
The compiler will then find them.


Michael.
--
___
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus