You are not logged in.
In situations where a dedicated webserver is impractical, it would be useful to have an application that can serve the static client files (.html, .css, .js etc.) as well as the database requests.
The following approach seems to work however it feels like a kludge; what is the best way to do this?
Example: start with FishFacts demo (Sample #19)
Define custom server
TCustomServer = class(TSQLHttpServer)
public
function Request(Ctxt: THttpServerRequest): cardinal; override;
end;
function TCustomServer.Request(Ctxt: THttpServerRequest): cardinal;
var
FileName: TFileName;
isDynamic: Boolean;
begin
isDynamic := True;
if (Ctxt.Method='GET') then
begin
FileName := Ctxt.URL;
if (FileName ='/') then
FileName := '/index.html';
FileName := ExeVersion.ProgramFilePath + 'html5' + FileName;
if FileExists(FileName) then
begin
// Serve the static files
isDynamic := False;
Ctxt.OutContent := StringToUTF8(FileName);
Ctxt.OutContentType := HTTP_RESP_STATICFILE;
result := 200;
end;
end;
if isDynamic then
// call the associated TSQLRestServer instance(s)
result := inherited Request(Ctxt);
end;
Change server definition and creation
//Server: TSQLHttpServer;
Server: TCustomServer;
Server := TCustomServer.Create('8080',[DB],'+',useHttpApiRegisteringURI);
In client browser
Simply open 192.168.0.63:8080 to start the client application.
(Where application server's IP address is 192.168.0.63)
Offline
> In situations where a dedicated webserver is impractical, it would be useful to have an application that can serve the
> static client files (.html, .css, .js etc.) as well as the database requests.
> The following approach seems to work however it feels like a kludge; what is the best way to do this?
I do the same for static files but for DB request, services are easier to use than these direct access.
BTW for static files, take a look at this topic: https://synopse.info/forum/viewtopic.php?id=3365
There was some talk about integrating this boilerplate into mORMot but nothing happened after.
Offline
for DB request, services are easier to use than these direct access.
I'm not quite sure what you mean; how would you implement this for the FishFacts demo for example?
BTW for static files, take a look at this topic: https://synopse.info/forum/viewtopic.php?id=3365
That looks very interesting, thanks Igor!
(Unfortunately it isn't compatible with Delphi 7, as it has records with methods).
Offline
> I'm not quite sure what you mean; how would you implement this for the FishFacts demo for example?
Sorry I wasn't precise, I meant interface services:
https://synopse.info/files/html/Synopse … ml#TITL_63
Last edited by igors233 (2018-07-03 06:49:19)
Offline
You can server static files from a method-based service (the easiest / preferred).
Or you may use an interface-based service with a function with a TServiceCustomAnswer record as result, so that you could set STATICFILE_CONTENT_TYPE and the filename as body.
Offline
Thanks Igor and Arnaud!
Offline