#1 2017-11-08 22:39:19

ianc
Member
Registered: 2017-01-12
Posts: 17

URL info requred

I have my first SOA application working with authentication, and database services working correctly on localhost.

aModel := TSQLModel.Create([TSQLAuthGroup, TSQLAuthUser, TPeople, Tcust], ROOT_NAME);
  try
    AServer := TSQLRestServerDB.Create(aModel, ChangeFileExt(ExeVersion.ProgramFileName, '.db3'), True, '');
    aHTTPServer := TSQLHttpServer.Create(PORT_NAME, [AServer], '+', useHttpApiRegisteringURI);
    TSQLRestServerDB(AServer).CreateMissingTables; 

This URL ///C:/PEWeb/PeMor/Server/files/peweb.html runs my login page correctly

This URL http://192.168.12.131/files/peweb.html
produces this result with the fiddler running

[Fiddler] ReadResponse() failed: The server did not return a complete response for this request. Server returned 0 bytes.

What would the correct URL be to access the login page which is generated by peweb.html 
Im trying to run the server on an intranet 

Hope this makes sense, Can anyone help - thanks

Offline

#2 2017-11-09 08:34:10

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,207
Website

Re: URL info requred

You need to publish the html static page via the HTTP server.
The easiest is to define a method-based service and using e.g. TSQLRestServerURIContext.ReturnFileFromFolder

Offline

#3 2017-11-09 21:12:24

ianc
Member
Registered: 2017-01-12
Posts: 17

Re: URL info requred

Hi All

I guess this is where I really start to learn.

After Reading up about ReturnFileFromFolder and method based services. ive understood from your reply that I need to add a method to my TSQLRestServerDB

 
   type
    TMyServer = class(TSQLRestServerDB)
    published
    procedure Html(Ctxt: TSQLRestServerURIContext);
  end;

  procedure TMyServer.Html(Ctxt: TSQLRestServerURIContext);
  begin
    Ctxt.ReturnFileFromFolder('C:\PEWeb');
  end; 

in the code in the previous post
ive changed the line to
AServer := TMyServer.Create(aModel, ChangeFileExt(ExeVersion.ProgramFileName, '.db3'), True, '');

Not sure how to implement or even if im on the right track

Ive tried various implementations to no avail crashing the server spectacular, Am I on the right track.

Offline

#4 2017-11-09 22:14:05

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,207
Website

Re: URL info requred

Could you please define what 'crashing the server' means?

Sounds fine to me, as far as I can guess from the code you did show...
It follows https://synopse.info/files/html/Synopse … ml#TITL_95

Offline

#5 2017-11-09 23:08:50

ianc
Member
Registered: 2017-01-12
Posts: 17

Re: URL info requred

Hi AB

A bit of over dramatization Im sure its my code that crashed it.

This was the log

20171109 19555609 DB    pe.TMyServer(020AD560) CreateMissingTables on {"TSQLDatabase(0218ABC8)":{"FileName":"C:\\PEWeb\\PeMor\\Server\\pe.db3","IsMemory":false,"UseCache":true,"TransactionActive":false,"BusyTimeout":0,"CacheSize":10000,"PageSize":4096,"PageCount":11,"FileSize":45056,"WALMode":false,"Synchronous":"smFull","LockingMode":"lmNormal","MemoryMappedMB":0,"user_version":0,"OpenV2Flags":6,"BackupBackgroundInProcess":false,"BackupBackgroundLastTime":"","BackupBackgroundLastFileName":"","SQLite3Library":{"TSQLite3LibraryStatic(02060030)":{"Version":"3.19.2 with internal MM"}}}}
20171109 19555609 DB    pe.TMyServer(020AD560) "GetTables":["AuthGroup","AuthUser","cust","People"]
20171109 19555609 trace pe.TMyServer(020AD560) BeginCurrentThread(THttpApiServer) root=root ThreadID=00001348 ThreadCount=32
20171109 19561314 EXCOS EAccessViolation (C0000005) at 005F8AC7  stack trace API 0056165B 00561684 0040B7B6 77096D4B 77096BD7 009B3692 009C59E4 769FEF8C 770B367A 770B364D 

This was because I really do not know how to implement the method in my code TMyServer.Html(Ctxt: TSQLRestServerURIContext);
I used

AServer.html(aCtxt);  

after

TSQLRestServerDB(AServer).CreateMissingTables;

Sorry for so much code in post

Offline

#6 2017-11-10 08:59:20

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,207
Website

Re: URL info requred

What does

I used

AServer.html(aCtxt);  

mean?

The service is to be called on client side, not on server side.

Offline

#7 2017-11-10 16:28:13

ianc
Member
Registered: 2017-01-12
Posts: 17

Re: URL info requred

Thanks AB

Now I understand

Offline

#8 2017-11-12 15:12:27

ianc
Member
Registered: 2017-01-12
Posts: 17

Re: URL info requred

Hi AB

I have implemented on the client side

 
type
  TMyClient = class(TSQLHttpClient)
    procedure DoMyObject(ahtml: TObject);
  end;

procedure TMyClient.DoMyObject(ahtml: TObject);
var err: integer;
begin
  Not sure what goes here
end;

Sorry to bother but I cant find doc or example of how to return the static HTML file in the client

Offline

#9 2017-11-13 13:29:10

igors233
Member
Registered: 2012-09-10
Posts: 234

Re: URL info requred

Try something like this below, this is untested code.

  // Server part
type
    TMyServer = class(TSQLRestServerDB)
    published
    procedure Html(Ctxt: TSQLRestServerURIContext);
  end;

  procedure TMyServer.Html(Ctxt: TSQLRestServerURIContext);
  var 
    FN: TFileName;
  begin
    FN := Ctxt.ResourceFileName;
    if FN = '' then
      FN := index.html; 

    Ctxt.ReturnFile('C:\PathToDirWithStaticFiles\' + FN, True);
  end;     

Then start your browser and type
http://localhost:80/html/index.html

You can also take a look at Project04ServerStatic.dpr from Samples dir.

And take a look at Boilerplate Delphi implementation that allows you to store static contents inside your exe file (as resources),
https://synopse.info/forum/viewtopic.ph … 285#p24285

Offline

#10 2017-11-14 00:29:39

ianc
Member
Registered: 2017-01-12
Posts: 17

Re: URL info requred

Hi Igor

Thank you very much for the advice, I tried but with no success
I implemented the server code from sample 4 in my server. the server runs and the logs say all is good. but i can still only access my HTML file by double clicking it. All works correctly then I am able to log in with mormot security and all my soa services function.
This URL is  ///C:/PEWeb/PeMor/Server/files/peweb.html

From my train of thought. The class and procedure TMyServer.Html(Ctxt: TSQLRestServerURIContext); Are declared in the server
Surely the client must call this procedure on the server. It this code that I don't know how to implement.???

My HTML file is generated in a Web Elevate app and my interface to mormot functions on all levels accept when trying to set the URL
http://192.168.12.131/files/peweb.html

Im assuming that the root folder is where my server executable is run from.

Apology's for my lack of understanding. I loaded Delphi Berlin starter about a year ago and am really enjoying pascal program and appreciate your patience.

Offline

Board footer

Powered by FluxBB