Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions Examples/LCL/Tutorial1/source/TestProject.lpi
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="Brookframework Test Server"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units>
<Unit>
<Filename Value="TestProject.lpr"/>
<IsPartOfProject Value="True"/>
</Unit>
<Unit>
<Filename Value="httpserver.pas"/>
<IsPartOfProject Value="True"/>
</Unit>
<Unit>
<Filename Value="routeping.pas"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<Target>
<Filename Value="TestProject"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<OtherUnitFiles Value="../../../../Source"/>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
</Debugging>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>
69 changes: 69 additions & 0 deletions Examples/LCL/Tutorial1/source/TestProject.lpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
program TestProject;

{$mode objfpc}{$H+}

uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
Classes, SysUtils, CustApp, httpserver, routeping
{ you can add units after this };

type

{ TBrookframeworkTest }

TBrookframeworkTest = class(TCustomApplication)
protected
procedure DoRun; override;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
end;

{ TBrookframeworkTest }

procedure TBrookframeworkTest.DoRun;
var
server: THTTPServer;
begin
server := THTTPServer.Create(nil);
try
server.SetupServer;
server.Open;
if not server.Active then
begin
WriteLn('Unable to start server at http://localhost:', server.Port);
Terminate(-1);
end
else
begin
WriteLn('Server running at http://localhost:', server.Port);
ReadLn;
end;
finally
server.Free;
end;
Terminate;
end;

constructor TBrookframeworkTest.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
StopOnException:=True;
end;

destructor TBrookframeworkTest.Destroy;
begin
inherited Destroy;
end;

var
Application: TBrookframeworkTest;
begin
Application:=TBrookframeworkTest.Create(nil);
Application.Title:='Brookframework Test Server';
Application.Run;
Application.Free;
end.

57 changes: 57 additions & 0 deletions Examples/LCL/Tutorial1/source/httpserver.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
unit httpserver;

{$mode ObjFPC}{$H+}

interface

uses
Classes, SysUtils,
BrookHTTPServer, BrookHTTPRequest,
BrookHTTPResponse, BrookURLRouter, BrookUtility;

type

{ THTTPServer }

THTTPServer = class(TBrookHTTPServer)
private
FRouter : TBrookURLRouter;
protected
procedure DoRequest(ASender: TObject; ARequest: TBrookHTTPRequest;
AResponse: TBrookHTTPResponse); override;
public
constructor Create(AOwner: TComponent); override;

procedure SetupServer;
end;


implementation

uses
routeping;

{ THTTPServer }

procedure THTTPServer.DoRequest(ASender: TObject; ARequest: TBrookHTTPRequest; AResponse: TBrookHTTPResponse);
begin
FRouter.Route(ASender, ARequest, AResponse);
end;

constructor THTTPServer.Create(AOwner: TComponent);
var
rp : TRoutePing;
begin
inherited Create(AOwner);
FRouter := TBrookURLRouter.Create(Self);
rp := TRoutePing.Create(FRouter.Routes);
FRouter.Active := true;
end;

procedure THTTPServer.SetupServer;
begin
Self.Port := 8080;
end;

end.

40 changes: 40 additions & 0 deletions Examples/LCL/Tutorial1/source/routeping.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
unit routeping;

{$mode ObjFPC}{$H+}

interface

uses
BrookUtility,
BrookHTTPRequest,
BrookHTTPResponse,
BrookURLRouter;

type

{ TRoutePing }

TRoutePing = class(TBrookURLRoute)
protected
procedure DoRequest(ASender: TObject; ARoute: TBrookURLRoute; ARequest: TBrookHTTPRequest; AResponse: TBrookHTTPResponse); override;
public
procedure AfterConstruction; override;
end;

implementation

{ TRoutePing }

procedure TRoutePing.DoRequest(ASender: TObject; ARoute: TBrookURLRoute; ARequest: TBrookHTTPRequest; AResponse: TBrookHTTPResponse);
begin
AResponse.Send('<html><head><title>Ping</title></head><body>Pong</body></html>', 'text/html; charset=utf-8', 200);
end;

procedure TRoutePing.AfterConstruction;
begin
Methods:= [rmGET];
Pattern:= '/ping';
end;

end.

70 changes: 70 additions & 0 deletions Examples/LCL/Tutorial1/source_https/TestProject.lpi
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="Brookframework Test Server"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units>
<Unit>
<Filename Value="TestProject.lpr"/>
<IsPartOfProject Value="True"/>
</Unit>
<Unit>
<Filename Value="httpserver.pas"/>
<IsPartOfProject Value="True"/>
</Unit>
<Unit>
<Filename Value="routeping.pas"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<Target>
<Filename Value="TestProject"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<OtherUnitFiles Value="../../../../Source"/>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
</Debugging>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>
69 changes: 69 additions & 0 deletions Examples/LCL/Tutorial1/source_https/TestProject.lpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
program TestProject;

{$mode objfpc}{$H+}

uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
Classes, SysUtils, CustApp, httpserver, routeping
{ you can add units after this };

type

{ TBrookframeworkTest }

TBrookframeworkTest = class(TCustomApplication)
protected
procedure DoRun; override;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
end;

{ TBrookframeworkTest }

procedure TBrookframeworkTest.DoRun;
var
server: THTTPServer;
begin
server := THTTPServer.Create(nil);
try
server.SetupServer;
server.Open;
if not server.Active then
begin
WriteLn('Unable to start server at https://localhost:', server.Port);
Terminate(-1);
end
else
begin
WriteLn('Server running at https://localhost:', server.Port);
ReadLn;
end;
finally
server.Free;
end;
Terminate;
end;

constructor TBrookframeworkTest.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
StopOnException:=True;
end;

destructor TBrookframeworkTest.Destroy;
begin
inherited Destroy;
end;

var
Application: TBrookframeworkTest;
begin
Application:=TBrookframeworkTest.Create(nil);
Application.Title:='Brookframework Test Server';
Application.Run;
Application.Free;
end.

Loading
Loading