-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.pas
More file actions
84 lines (66 loc) · 1.18 KB
/
Copy pathserver.pas
File metadata and controls
84 lines (66 loc) · 1.18 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
unit server;
interface
uses
system.sysutils;
type
TServer = class
private
constructor create;
destructor destroy; override;
public
procedure Initialize;
procedure Stop;
class function Instance: TServer;
end;
implementation
uses
horse,
horse.cors,
Horse.Jhonson,
Horse.GBSwagger,
documentation.config,
route,
GBJSON.Config;
var
FInstance: TServer = nil;
{ TServer }
constructor TServer.create;
begin
THorse
.Use(CORS)
.Use(Jhonson())
.Use(HorseSWagger);
TRoute.Resgiter;
TGBJSONConfig.GetInstance.DateTimeFormat('dd/mm/yyyy hh:mm:ss');
TGBJSONConfig.GetInstance.DateTimeLocale('pt-BR');
end;
destructor TServer.destroy;
begin
inherited;
end;
procedure TServer.Initialize;
var
Port: integer;
begin
Port := 4040;
Thorse.Listen(Port,
procedure
begin
writeln(format('API runing in port: %d',[Port]));
end)
end;
class function TServer.Instance: TServer;
begin
if not Assigned(FInstance) then
FInstance := Self.create;
Result := FInstance;
end;
procedure TServer.Stop;
begin
THorse.StopListen;
end;
initialization
finalization
if Assigned(FInstance) then
FreeAndNil(FInstance);
end.