* Allow to specify address

This commit is contained in:
Michaël Van Canneyt 2021-09-15 11:22:52 +02:00
parent 711e659f5c
commit 3e621f2014

View File

@ -100,6 +100,7 @@ Type
FPassword:String;
FEcho:Boolean;
FMaxAge: integer;
FInterfaceAddress : String;
procedure AddToStatus(O: TJSONObject);
procedure DoEcho(ARequest: TRequest; AResponse: TResponse);
procedure DoProxyLog(Sender: TObject; const aMethod, aLocation, aFromURL, aToURL: String);
@ -133,6 +134,7 @@ Type
Property MimeFile : String Read FMimeFile;
Property NoIndexPage : Boolean Read FNoIndexPage Write FNoIndexPage;
Property IndexPageName : String Read FIndexPageName Write FIndexPageName;
Property InterfaceAddress : String Read FInterfaceAddress Write FInterfaceAddress;
end;
@ -281,6 +283,7 @@ begin
Writeln(' Default is current working directory: ',GetCurrentDir);
Writeln('-h --help This help text');
Writeln('-i --indexpage=name Directory index page to use (default: index.html)');
Writeln('-I --interface=IP Listen on this interface address only.');
Writeln('-m --mimetypes=file Set Filename for loading mimetypes. Default is ',GetDefaultMimeTypesFile);
Writeln('-n --noindexpage Do not allow index page.');
Writeln('-p --port=NNNN TCP/IP port to listen on (default is 3000)');
@ -639,6 +642,7 @@ Const
SLocations = 'Locations';
KeyPort = 'Port';
KeyInterface = 'Interface';
KeyDir = 'Directory';
KeyIndexPage = 'IndexPage';
KeyHostName = 'hostname';
@ -664,6 +668,7 @@ begin
try
FBaseDir:=ReadString(SConfig,KeyDir,BaseDir);
Port:=ReadInteger(SConfig,KeyPort,Port);
InterfaceAddress:=ReadString(SConfig,KeyInterface,InterfaceAddress);
Quiet:=ReadBool(SConfig,KeyQuiet,Quiet);
FMimeFile:=ReadString(SConfig,keyMimetypes,MimeFile);
NoIndexPage:=ReadBool(SConfig,KeyNoIndexPage,NoIndexPage);
@ -717,6 +722,7 @@ begin
D:=GetCurrentDir;
if HasOption('m','mimetypes') then
MimeTypesFile:=GetOptionValue('m','mimetypes');
if MimeTypesFile='' then
begin
MimeTypesFile:=GetDefaultMimeTypesFile;
@ -740,6 +746,8 @@ begin
NoIndexPage:=NoIndexPage or HasOption('n','noindexpage');
if HasOption('i','indexpage') then
IndexPage:=GetOptionValue('i','indexpage');
if HasOption('I','interface') then
InterfaceAddress:=GetOptionValue('I','interface');
If not NoIndexPage then
begin
if (IndexPage='') then
@ -800,6 +808,8 @@ begin
Log(etError,'API support missing, Compile with fpc 3.3.1+');
{$ENDIF}
TSimpleFileModule.RegisterDefaultRoute;
if InterfaceAddress<>'' then
HTTPHandler.Address:=InterfaceAddress;
inherited;
end;