unit Sparkle.Comp.StaticServer;

interface

uses
  Sparkle.Comp.Server,
  Sparkle.HttpServer.Module,
  Sparkle.Module.Static;

type
  TStaticModuleEvent = procedure(Sender: TObject; Module: TStaticModule) of object;

  TSparkleStaticServer = class(TSparkleServer)
  private
    FRootDir: string;
    FOnModuleCreate: TStaticModuleEvent;
  protected
    function CreateSparkleModule: THttpServerModule; override;
    procedure DoModuleCreate(Module: THttpServerModule); override;
  published
    property RootDir: string read FRootDir write FRootDir;
    property BaseUrl;
    property Dispatcher;
    property OnModuleCreate: TStaticModuleEvent read FOnModuleCreate write FOnModuleCreate;
  end;

implementation

{ TSparkleStaticServer }

function TSparkleStaticServer.CreateSparkleModule: THttpServerModule;
begin
  Result := TStaticModule.Create(Self.BaseUrl, Self.RootDir);
end;

procedure TSparkleStaticServer.DoModuleCreate(Module: THttpServerModule);
begin
  if Assigned(FOnModuleCreate) then
    FOnModuleCreate(Self, Module as TStaticModule);
end;

end.
