#1 2024-07-25 08:35:53

Flashcqxg
Member
Registered: 2018-01-11
Posts: 31

About ReturnFileFromFolder in mORMot2

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

Offline

#2 2024-07-25 09:47:34

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,492
Website

Re: About ReturnFileFromFolder in mORMot2

You are messing with REST and HTTP servers, with a lot of confusion.

Take a look at
https://github.com/synopse/mORMot2/tree … rver-files
https://github.com/synopse/mORMot2/tree … server-raw

From our tests, our IOCP server is faster than http.sys on Windows.

Offline

#3 2024-07-27 12:35:13

mormoter
Member
Registered: 2024-06-14
Posts: 20

Re: About ReturnFileFromFolder in mORMot2

procedure TSampleServer1.Example(C: TRestServerUriContext);
begin
  C.ReturnFileFromFolder('d:\www');
end;

why it doesnt work?

Offline

#4 2024-07-27 13:35:41

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,492
Website

Re: About ReturnFileFromFolder in mORMot2

You are using a REST server.
You need to register the published method - which I guess you don't.

If you take 5 minutes to look at the samples linked above, you will find the right pure HTTP class to use.

Offline

Board footer

Powered by FluxBB