You are not logged in.
Pages: 1
My code is as follows, which was written in the reference forum
https://synopse.info/forum/viewtopic.php?id=2234
When I use a browser to access: http://127.0.0.1:8888/root/Example ,
Browser error prompt:
GET http://127.0.0.1:8888/assets/index -536d3432.js net::ERR_ABORTED 503 (Service Unavailable)
GET http://127.0.0.1:8888/assets/index -71dc7c95.css net::ERR_ABORTED 503 (Service Unavailable)
GET http://127.0.0.1:8888/favicon.ico 503 (Service Unavailable)
If I put the d: \ www directory into IIS, the browser can access it normally.
What can I do to make Mormot a web server, so that I don't have to install IIS, Apache or NGinx, just a simple mORMot executable is able to do web services and API services.
Thanks.
type
TSampleServer1 = class(TRestServerFullMemory)
published
procedure Example(C: TRestServerUriContext);
end;
procedure TSampleServer1.Example(C: TRestServerUriContext);
begin
C.ReturnFileFromFolder('d:\www');
end;
SampleServer := TSampleServer1.CreateWithOwnModel([], False, 'root');
HttpServer := TRestHttpServer.Create('8888', [], '+', HTTP_DEFAULT_MODE, 4);
HttpServer.AddServer(SampleServer);
Hi,
ab,What should safe code look like?and how to register the URI use code?
Oh, Mormot is so powerful, but its reference manual and demo are so few, making it difficult for beginners of Delphi to quickly get started.
Thanks for your help.
I just delphi the static files the DoOnRequest:
function TGEApiServer.DoOnRequest(C: THttpServerRequestAbstract): cardinal;
var
sFile: string;
begin
var sUrl := UrlDecode(C.URL);
sFile := ExtractFilePath(ParamStr(0)) + 'dist\' + sUrl;
if FileExists(sFile) then
begin
Result := C.SetOutFile(sFile, False);
end
else if FileExists(sFile + '\index.html') then
begin
// eg: http://17.0.0.1 = http://127.0.0.1/index.html
sFile := sFile + '\index.html';
Result := C.SetOutFile(sFile, False);
end
else if sUrl = '/login' then
begin
Result := C.SetOutFile('.\dist\index.html', False);
end
else
begin
Result := 200;
end;
end;
What I mean is: I put some static files such as HTML, JS, CSS in the www directory and use THttpApiServer as a static web server. Currently, using SetOutContent (StringFromFile()) cannot achieve the goal.
I am using SetOutContent(StringFromFile()),but it cannot output web pages properly.
The static files is not compressed in the DoOnRequest:
function TGEApiServer.DoOnRequest(C: THttpServerRequestAbstract): cardinal;
var
sFile: string;
begin
var sUrl := UrlDecode(C.URL);
sFile := ExtractFilePath(ParamStr(0)) + 'dist\' + sUrl;
if FileExists(sFile) then
begin
Result := C.SetOutFile(sFile, False);
end
else if FileExists(sFile + '\index.html') then
begin
// eg: http://17.0.0.1 = http://127.0.0.1/index.html
sFile := sFile + '\index.html';
Result := C.SetOutFile(sFile, False);
end
else if sUrl = '/login' then
begin
Result := C.SetOutFile('.\dist\index.html', False);
end
else
begin
Result := 200;
end;
end;
The first problem has been solved. The second issue has not been resolved, as the output static HTML file is not compressed.
How to register the URL as http.sys level? the code fHttpServer.add can't be registered?
The code is as follows:
fHttpServer := THttpApiServer.Create('');
fHttpServer.RegisterCompress(CompressGZip, 10);
fHttpServer.RegisterCompress(CompressDeflate, 10);
fHttpServer. AddUrl('', '8888', False, '127.0.0.1');
// fHttpServer. AddUrl('', '8888', False, '*');
//fHttpServer.AddUrl('', '8888', False, '+');
1. Whether I use * or+, the following three methods cannot be accessed:
http://127.0.0.1:8888
http://localhost:8888
http://192.168.1.9:8888 (Local intranet IP address)
2. After using Register Compress, use Ctxt.SetOutFile send a static file to the browser,but that has not been compressed.
Thank you.
thanks.
Can THttpApiServer or THttpAsyncServer use sessions to store user information? For example, storing user accounts, user department IDs, user login IPs, login times, etc.
If possible, how can I use it?
thank you.
thanks.
TMS Sparkle provides classes that allow you to create middleware interfaces and add them to the request processing pipeline. In other words, you can add custom functionality that preprocess the request before it's effectively processed by the main server module, and postprocess the response provided by it.
Does mORMot2 have middleware similar to this?
I test with the TPdfDocumentGdi , and set the i from 1 to 70000,it out of memory!
var
// PDF: TPdfDocument;
PDF: TPdfDocumentGDI;
PDFPage: TPdfpage;
SW: TStopwatch;
I: Integer;
FS: TFileStream;
pdfImage: TPdfImage;
BarCode: string;
X, Y: Single;
aRect: TRect;
begin
SW := TStopwatch.StartNew;
PDF := TPdfDocumentGDI.Create;
// PDF := TPdfDocument.Create;
FS := TFileStream.Create(ExtractFilePath(Application.ExeName) + 'output.pdf', fmCreate);
try
PDF.NewDoc;
PDF.PDFA1 := True;
PDF.DefaultPaperSize := psA4;
PDF.SaveToStreamDirectBegin(FS);
aRect := Rect(Point(20, 40), Point(60, 80));
for I := 1 to 70000 do
begin
PDF.AddPage;
BarCode := IdGenerator.NextId.ToString;
GDICommentJpegDirect(PDF.VCLCanvas.Handle, 'd:\test.jpg', aRect);
PDF.SaveToStreamDirectPageFlush(True);
end;
PDF.SaveToStreamDirectEnd;
Memo1.Lines.Add(SW.ElapsedMilliseconds.ToString);
finally
PDF.Free;
FS.Free;
end;
My code is as follows, the image test.jpg is only 5kb in size. The program ran for more than 10 minutes, but did not receive the expected PDF file. Finally, it indicated that there was insufficient memory.
How can I improve it? Thank you!
var
PDF: TPdfDocument;
PDFPage: TPdfpage;
SW: TStopwatch;
I: Integer;
FS: TFileStream;
pdfImage: TPdfImage;
BarCode: string;
X, Y: Single;
begin
SW := TStopwatch.StartNew;
PDF := TPdfDocument.Create;
FS := TFileStream.Create(ExtractFilePath(Application.ExeName) + 'output.pdf', fmCreate);
try
PDF.NewDoc;
PDF.PDFA1 := True;
PDF.DefaultPaperSize := psA4;
PDF.SaveToStreamDirectBegin(FS);
for I := 1 to 30000 do
begin
PDF.AddPage;
BarCode := IdGenerator.NextId.ToString;
pdfImage := TPdfImage.CreateJpegDirect(PDF, 'd:\test.jpg', True);
PDF.AddXObject(BarCode, pdfImage);
X := 200;
Y := 800;
PDF.Canvas.DrawXObject(X, Y, 30, 30, BarCode);
pdfImage.ForceSaveNow;
PDF.SaveToStreamDirectPageFlush(True);
end;
PDF.SaveToStreamDirectEnd;
Memo1.Lines.Add(SW.ElapsedMilliseconds.ToString);
finally
PDF.Free;
FS.Free;
end;
thank you,it works!
my code:
var
PDF: TPdfDocument;
R: TPdfRect;
R.Left := 30;
R.Top := 500;
R.Right := 100;
R.Bottom := 800;
PDF.Canvas.SetFont('Times New Roman', 12, []);
PDF.Canvas.MultilineTextRect(R, 'Welcome to mORMot Open Source', True);
Only the text 'Welcome to' is displayed, no other text is displayed.
Thanks.
Thanks,ab.
My code:
var
props: TSQLDBWinHTTPConnectionProperties;
SQL: TStringBuilder;
begin
props := TSQLDBWinHTTPConnectionProperties.Create('127.0.0.1', 'XXX', '123', '123');
SQL := TStringBuilder.Create;
DD := TSynDBDataSet.Create(self);
DD.Connection := props;
SQL.Append('SELECT XGSTUFSID,XM,').AppendLine;
SQL.Append('CASE WHEN SUBSTRING(BKZYDM,3,1) IN(''5'',''6'') THEN ''2'' ELSE ''1'' END LX').AppendLine;
SQL.Append('FROM BBK').AppendLine;
DD.CommandText := SQL.ToString;
DD.Open;
When I modify the field of XM,and call Post and ApplyUpdates(0),but no data was saved.
How can i do ?Thanks.
Hi:
EgonHugeist,Can you send a copy of the updated the Native ASA driver of zeos for V17 to me?My Email:51536348@qq.com.
Thanks!
Just a note from me: I've updated the Native ASA driver of zeos for V17. Also did i add a new driver with protocol name "asa_capi" for the recommended sybase api.
Are you sure that the 40,000 records are actually fetched, and not only the first dozen, just enough to be displayed?
We don't use open cursors (which tend to put any DB server on its knees when too much cursors are opened at once), but fetch all records as JSON and close the statement ASAP.
If it is too big/slow, reduce the number of records fetched by using paging.I am not convinced that NativeDB is faster than FireDAC or Zeos. Usually, Zeos is faster than anything else on Delphi.
For instance, ZDBC or our SynDB classes are like NativeDB in concept: it bypasses the DB.pas unit and TDataSet.
I still suppose you are not fetching all rows, just the first ones.
For SQL Anywhere 17, I believe NativeDB is the fastest, this can be verified by testing.
So,currently,NativeDB is the best solution to access SAP SQL Anywhere.
Zeos can connect to the database, but it prompts an error when querying and failed.
The NativeDB query statement is the same as FireDAC, and the total amount of data to be obtained in the end is similar to the following code:
query.sql.add ('select * from test');
query.open();
query.fecthall();//for firedac
memo.lines.add (query.recordcont.tostring);
"Slow" is relative, mainly because NativeDB is too fast. I have tested, access SQL Anywhere on local machine, take out 40,000 records, NativeDB only needs 6-11ms, and FireDAC needs 700-900ms. As the server side, this speed experience is very obvious. Therefore, I hope to increase the NativeDB driver, thanks.
You can try SynDBOleDB, SynDBODBC or SynDBZeos. Hope all of them can connect to Sybase.
Thank you,they are too slow.
Hello:
NativeDB is a special drive for Sybase SQL Anywhere and extremely fast,NativeDB see http://www.nativedb.com/.
I want to use it for TSQLDBServerHttpApi,although now using TSQLDBFireDACConnectionProperties can connect to Sybase SQL Anywhere, but it's speed is relatively slow, far less than NativeDB.
Hope to add the NativeDB driver support for Sybase SQL Anywhere.
Thank a lot!
Thank you,i'll try to do it.
Hello:
I am a new user of mormot,and more interested in TSQLDBServerHttpApi.
I want to use redis as a session manager for TSQLDBServerHttpApi,clients that have not passed session authentication cannot access the TSQLDBServerHttpApi server,BUT:
1) How to combine this redis session manager with TSQLDBServerHttpApi?
2) How does the client carry the session to access TSQLDBServerHttpApi
Thanks!
It's work well.
Thank!
It is not supported yet.
What is the closest SQL dialect?
It's Transact-SQL ,like MS SQL.
Hope to support it as soon as possible.
Thanks a lot!
I wanted to connect to SAP SQL Anywhere 17 by TSQLDBFireDACConnectionProperties:
var
FD: TSQLDBFireDACConnectionProperties;
FD := TSQLDBFireDACConnectionProperties.Create('ASA?ENG=test', 'TEST',
'dba', 'sql');
Error Message:
TSQLDBFireDACConnectionProperties.Create:unknown provider-available: OraMSSQLMSAccMySQLSQLiteIBPGDB2Infx.
How to connect to the SAP SQL Anywhere 17 by TSQLDBFireDACConnectionProperties?
Thanks.
Pages: 1