delphimvcframework/samples/server_in_dll/REST/REST.RestServer.pas
2019-05-19 14:06:28 +02:00

70 lines
1.3 KiB
ObjectPascal

unit REST.RestServer;
interface
uses
System.SysUtils,
MVCFramework,
MVCFramework.Logger,
MVCFramework.Commons,
MVCFramework.REPLCommandsHandlerU,
Web.WebReq,
Web.WebBroker,
IdHTTPWebBrokerBridge;
type
TDMVCRestServer = class
private
fServer: TIdHTTPWebBrokerBridge;
public
constructor Create(const aPort: integer); overload;
procedure Activate;
destructor Destroy; override;
end;
implementation
uses
REST.WebModule;
procedure TDMVCRestServer.Activate;
begin
fServer.Active := true;
if fServer.Active then
begin
LogD('Server active on port=' + IntToStr(fServer.DefaultPort));
end;
end;
constructor TDMVCRestServer.Create(const aPort: integer);
begin
inherited Create;
fServer := TIdHTTPWebBrokerBridge.Create();
if WebRequestHandler <> nil then
begin
WebRequestHandler.WebModuleClass := WebModuleClass;
WebRequestHandlerProc.MaxConnections := 1024;
end;
fServer.DefaultPort := aPort;
end;
destructor TDMVCRestServer.Destroy;
begin
EnterInShutdownState;
try
fServer.Active := false;
FreeAndNil(fServer);
LogD('Server not active');
except
on E: Exception do
begin
LogE('[TDMVCRestServer.Destroy] ' + E.Message);
end;
end;
ReleaseGlobalLogger;
inherited Destroy;
end;
end.