#1 mORMot 2 » About ReturnFileFromFolder in mORMot2 » 2024-07-25 08:35:53

Flashcqxg
Replies: 3

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);

#2 Re: mORMot 2 » Two questions about THttpApiServer » 2024-07-22 23:30:15

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.

#3 Re: mORMot 2 » Two questions about THttpApiServer » 2024-07-22 14:15:23

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;

#4 Re: mORMot 2 » Two questions about THttpApiServer » 2024-07-22 12:58:51

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.

#5 Re: mORMot 2 » Two questions about THttpApiServer » 2024-07-22 10:08:18

I am using SetOutContent(StringFromFile()),but it cannot output web pages properly.

#6 Re: mORMot 2 » Two questions about THttpApiServer » 2024-07-22 03:38:39

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;

#7 Re: mORMot 2 » Two questions about THttpApiServer » 2024-07-21 08:57:23

The first problem has been solved. The second issue has not been resolved, as the output static HTML file is not compressed.

#8 Re: mORMot 2 » Two questions about THttpApiServer » 2024-07-20 22:48:23

How to register the URL as http.sys level? the code fHttpServer.add can't be registered?

#9 mORMot 2 » Two questions about THttpApiServer » 2024-07-20 08:59:57

Flashcqxg
Replies: 12

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.

#11 mORMot 2 » Can THttpApiServer or THttpAsyncServer use sessions to store user info » 2024-07-13 02:13:28

Flashcqxg
Replies: 2

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.

#13 mORMot 2 » Does mORMot2 have middleware similar to TMS Sparkle » 2024-07-12 08:44:52

Flashcqxg
Replies: 3

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?

#14 Re: PDF Engine » PDF:AddXObject is slow and out of memory! » 2023-10-15 13:14:13

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;

#15 PDF Engine » PDF:AddXObject is slow and out of memory! » 2023-10-15 03:40:48

Flashcqxg
Replies: 3

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;

#17 PDF Engine » MultilineTextRect does not work correctly » 2023-06-26 14:10:14

Flashcqxg
Replies: 2

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.

#19 mORMot 1 » TSynDBDataSet:How to update data when there is an alias field ? » 2020-06-01 14:56:30

Flashcqxg
Replies: 2

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.

#20 Re: mORMot 1 » Hope to add the NativeDB driver support for Sybase SQL Anywhere » 2020-06-01 14:35:09

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!

EgonHugeist wrote:

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.

#21 Re: mORMot 1 » Hope to add the NativeDB driver support for Sybase SQL Anywhere » 2020-04-27 00:51:45

ab wrote:

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.

#22 Re: mORMot 1 » Hope to add the NativeDB driver support for Sybase SQL Anywhere » 2020-04-15 11:33:19

So,currently,NativeDB is the best solution to access SAP SQL Anywhere.

#23 Re: mORMot 1 » Hope to add the NativeDB driver support for Sybase SQL Anywhere » 2020-04-14 12:02:34

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);

#24 Re: mORMot 1 » Hope to add the NativeDB driver support for Sybase SQL Anywhere » 2020-04-14 11:36:01

"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.

#25 Re: mORMot 1 » Hope to add the NativeDB driver support for Sybase SQL Anywhere » 2020-04-14 00:39:23

mpv wrote:

You can try SynDBOleDB, SynDBODBC or SynDBZeos. Hope all of them can connect to Sybase.

Thank you,they are too slow.

#26 mORMot 1 » Hope to add the NativeDB driver support for Sybase SQL Anywhere » 2020-04-13 03:05:31

Flashcqxg
Replies: 14

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!

#28 mORMot 1 » TSQLDBServerHttpApi And Session verification » 2020-04-09 03:58:55

Flashcqxg
Replies: 2

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!

#30 Re: mORMot 1 » TSQLDBFireDACConnectionProperties and SAP SQL Anywhere 17 » 2020-04-05 14:15:34

ab wrote:

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!

#31 mORMot 1 » TSQLDBFireDACConnectionProperties and SAP SQL Anywhere 17 » 2020-04-05 10:51:49

Flashcqxg
Replies: 4

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.

Board footer

Powered by FluxBB