* Some command-line options

This commit is contained in:
Michaël Van Canneyt 2021-08-18 14:11:50 +02:00
parent 5bf9de22d6
commit f7265bf79e

View File

@ -7,7 +7,7 @@ uses
{$IFDEF UNIX}{$IFDEF UseCThreads} {$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads, cthreads,
{$ENDIF}{$ENDIF} {$ENDIF}{$ENDIF}
sysutils, Classes, fphttpserver, fpmimetypes, testhttpserver; sysutils, strutils,Classes, fphttpserver, fpmimetypes, testhttpserver;
Type Type
@ -35,17 +35,31 @@ begin
end; end;
begin begin
if IndexText(ParamStr(1),['-h','--help'])<>-1 then
begin
Writeln('Usage: ',ExtractFileName(ParamStr(0)),' [dir [port]]');
Writeln('Default dir is binary location');
Writeln('Default port is 8080');
Halt(0);
end;
Serv:=THTTPServer.Create(Nil); Serv:=THTTPServer.Create(Nil);
try try
Serv.BaseDir:=ExtractFilePath(ParamStr(0)); if ParamCount=0 then
Serv.BaseDir:=ExtractFilePath(ParamStr(0))
else
Serv.BaseDir:=ParamStr(1);
if ParamCount>1 then
Serv.Port:=StrToIntDef(ParamStr(2),8080)
else
Serv.Port:=8080;
{$ifdef unix} {$ifdef unix}
Serv.MimeTypesFile:='/etc/mime.types'; Serv.MimeTypesFile:='/etc/mime.types';
{$endif} {$endif}
Serv.Threaded:=False; Serv.ThreadMode:=tmThreadPool;
Serv.Port:=8080;
Serv.AcceptIdleTimeout:=1000; Serv.AcceptIdleTimeout:=1000;
Serv.OnAcceptIdle:=@Serv.DoIdle; Serv.OnAcceptIdle:=@Serv.DoIdle;
Serv.WriteInfo:=@Serv.DoWriteInfo; Serv.WriteInfo:=@Serv.DoWriteInfo;
Serv.EnableKeepAlive:=True;
Serv.Active:=True; Serv.Active:=True;
finally finally
Serv.Free; Serv.Free;