-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRestAPI.dpr
More file actions
92 lines (82 loc) · 2.48 KB
/
RestAPI.dpr
File metadata and controls
92 lines (82 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
program RestAPI;
{$APPTYPE CONSOLE}
{$WARN IMPLICIT_STRING_CAST OFF}
{$WARN IMPLICIT_STRING_CAST_LOSS OFF}
{$R *.res}
uses
System.SysUtils,
WinApi.Windows,
SynCommons,
SynTable,
SynCrypto,
mORMot,
mORMotHTTPServer,
mORMotService,
SynSQLite3Static,
Constants in 'Constants.pas',
MyService.Interfaces in 'MyService.Interfaces.pas',
MyService.Model in 'MyService.Model.pas',
Base.SQLConnectionProp in 'Base.SQLConnectionProp.pas',
MyService in 'MyService.pas',
Base.Service in 'Base.Service.pas',
Base.RestServer in 'Base.RestServer.pas',
Base.RestClient in 'Base.RestClient.pas',
MyAPIService in 'MyAPIService.pas',
MyAPIService.Interfaces in 'MyAPIService.Interfaces.pas';
const
SERVICE_Name = 'MyRestAPI_Service';
SERVICE_DESCRIPTION = 'MyRestAPI Service With Mormot';
var Param1: String;
begin
try
ConsoleWrite('Service starting...', ccYellow);
if (ParamCount<>0) then
begin
Param1 := ParamStr(1);
if (Param1 <> '') and (Param1[1] = '-') then
Param1[1] := '/';
if (SameText(Param1,'/h') or SameText(Param1,'/?')) then begin
TMyWinService.WriteHelpContent;
end
else
if (SameText(Param1,'/install') or SameText(Param1,'/uninstall') or SameText(Param1,'/start') or SameText(Param1,'/stop')) then
begin
TServiceController.CheckParameters(ExeVersion.ProgramFileName, ExeVersion.ProgramName, SERVICE_DESCRIPTION, SERVICE_DESCRIPTION);
with TServiceController.CreateOpenService('', '', ExeVersion.ProgramName) do
try
// TODO
State; // just to log the service state after handling the /parameters
finally
Free;
end;
end
else
if SameText(Param1,'/c') then
with TMyApiService.CreateAsConsole do
try
DoStart(nil);
writeln(#10);
ConsoleWrite('Service is running: PORT:8080', ccLightGreen);
ConsoleWrite('FULL_URL: http://localhost:8080/a/', ccLightGray);
ConsoleWrite('', ccLightGray);
ConsoleWrite('Press [Enter] to close the server', ccLightGray);
ConsoleWaitForEnterKey; // ReadLn if you do not use main thread execution
Exit;
finally
Free;
end;
end
else
begin
with TMyApiService.Create do
try
ServicesRun;
finally
Free;
end;
end;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.