Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Server Projects.
Thu, May 21 2020 2:00 AMPermanent Link

Steve Gill

Hi Tim,

I have been looking at Server Projects (File/New Project/Server Project) so I can test it but I'm not sure how these are supposed to work.  I assume this type of project will be explained at some stage (or maybe it already has and I missed it).

= Steve
Thu, May 21 2020 10:17 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Steve,

<< I have been looking at Server Projects (File/New Project/Server Project) so I can test it but I'm not sure how these are supposed to work.  I assume this type of project will be explained at some stage (or maybe it already has and I missed it). >>

Yes, this will be explained in the documentation.

The server applications work just like client applications in terms of the project layout, etc.  The main difference is that, instead of forms, you define request handlers.  It's probably going to be rare to have more than the main request handler in a server application, but you can do it if you want to split out the request handling into different dynamic routes in a server application.  The native request instance from the web server is passed directly into the request handler so that you can then use it to determine the request parameters, content, etc., as well as use the request instance to send a response back to the client.

Here is the main OnHandleRequest event handler in my test server application that I'm using in the beta:

procedure TReqHandler1.ReqHandler1HandleRequest(Sender: TObject; Request: TWebServerRequest);
var
  TempMethod: String;
begin
  with Request do
     begin
     TempMethod:=RequestParameters['method'];
     if (RequestMethod=hmGet) then
        begin
        if SameText(TempMethod,'testjson') then
           TestJSON(Request)
        else if SameText(TempMethod,'loaddataset') then
           LoadDataSet(Request)
        else if SameText(TempMethod,'sessionvar') then
           GetSessionVariable(Request)
        else
           SendError(HTTP_NOT_FOUND,'Method "'+TempMethod+'" does not exist');
        end
     else if (RequestMethod=hmPost) then
        begin
        if SameText(TempMethod,'deleterows') then
           DeleteRows(Request)
        else if SameText(TempMethod,'updaterows') then
           UpdateRows(Request)
        else if SameText(TempMethod,'uploadfile') then
           UploadFile(Request)
        else if SameText(TempMethod,'email') then
           SendMail(Request)
        else if SameText(TempMethod,'url') then
           SaveURL(Request)
        else
           SendError(HTTP_NOT_FOUND,'Method "'+TempMethod+'" does not exist');
        end
     else
        SendError(HTTP_BAD_REQUEST,'Invalid HTTP method "'+RequestMethodName+'"');
     end;
end;

There is one small difference between client and server applications: server applications must first be deployed (but not run) and then installed using the Server Manager.  After deploying the server application (Alt-F9), navigate to:

Server Manager -> Internal -> Applications

Right-click on Applications and select Install Application.  Give the application a name (this is the application's resource name in URLs) and select the deployed application using the button.

Once an application has been installed, you can then just deploy and/or run the application from the IDE as if you were running a client application.

There is also the requirement of creating a request to use for running the server application in the IDE for debugging, and I will cover that in the EWB 3 walkthrough video.

Tim Young
Elevate Software
www.elevatesoft.com
Fri, May 22 2020 12:54 AMPermanent Link

Steve Gill

Thanks Tim.

= Steve
Image