forked from synopse/mORMot2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMVCServerFirebirdZeos.dpr
95 lines (86 loc) · 2.82 KB
/
MVCServerFirebirdZeos.dpr
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
93
94
// MVC sample web application, publishing a simple BLOG
// - this program is a part of the Open Source Synopse mORMot framework 2,
// licensed under a MPL/GPL/LGPL three license - see LICENSE.md
program MVCServerFirebirdZeos;
{$I mormot.defines.inc}
{$ifdef OSWINDOWS}
{$apptype console}
{$R mormot.win.default.manifest.res}
{$endif OSWINDOWS}
uses
{$I mormot.uses.inc}
MVCModel in 'MVCModel.pas',
MVCViewModel in 'MVCViewModel.pas',
sysutils,
mormot.core.base,
mormot.core.rtti,
mormot.core.os,
mormot.db.raw.sqlite3,
mormot.db.raw.sqlite3.static,
mormot.db.sql.zeos,
mormot.orm.core,
mormot.orm.sql,
mormot.rest.http.server,
mormot.rest.sqlite3,
mormot.core.log, zdbc;
var
aModel: TOrmModel;
aExternalDB: TSqlDBZeosConnectionProperties;
aServer: TRestServerDB;
aApplication: TBlogApplication;
aHTTPServer: TRestHttpServer;
LogFamily: TSynLogFamily;
begin
LogFamily := TSynLog.Family;
LogFamily.Level := LOG_VERBOSE;
LogFamily.PerThreadLog := ptIdentifiedInOnFile;
//LogFamily.EchoToConsole := LOG_VERBOSE;
aModel := CreateModel;
try
aExternalDB := TSqlDBZeosConnectionProperties.Create(
'zdbc:firebird://localhost:3033/c:\temp\mvc_blog.fdb?'+
'username=SYSDBA;'+
'password=masterkey;'+
'LibLocation=C:\Firebird\firebird3_32\fbclient.dll;'+
'hard_commit=true', '', '', '' );
try
VirtualTableExternalRegisterAll(aModel,aExternalDB, [regMapAutoKeywordFields]);
aServer := TRestServerDB.Create(aModel, SQLITE_MEMORY_DATABASE_NAME);
try
aServer.Server.CreateMissingTables;
aApplication := TBlogApplication.Create;
try
aApplication.Start(aServer);
aApplication.HasFts:=False;
aHTTPServer := TRestHttpServer.Create('8092', aServer
{$ifdef USEHTTPSYS}, '+', useHttpApiRegisteringURI{$endif});
try
aHTTPServer.RootRedirectToURI('blog/default'); // redirect / to blog/default
aServer.RootRedirectGet := 'blog/default'; // redirect blog to blog/default
writeln('"MVC Blog Server" launched on port 8092 using ',
aHttpServer.HttpServer.ClassName);
writeln(#10'You can check http://localhost:8092/blog/mvc-info for information');
writeln('or point to http://localhost:8092 to access the web app.');
writeln(#10'Press [Enter] to close the server.'#10);
readln;
writeln('HTTP server shutdown...');
finally
aHTTPServer.Free;
end;
finally
aApplication.Free;
end;
finally
aServer.Free;
end;
finally
aExternalDB.Free;
end;
finally
aModel.Free;
end;
writeln('HTTP server finalized. Bye!');
{$ifdef FPC_X64MM}
WriteHeapStatus(' ', 16, 8, {compileflags=}true);
{$endif FPC_X64MM}
end.