procedure TForm1.OnRequest(Sender: TObject;
var ARequest: TFPHTTPConnectionRequest;
var AResponse: TFPHTTPConnectionResponse);
var
AFilename: String;
begin
AFilename := ARequest.URI;
{Get rid of the starting bars so we won't serve from '/'
Theres should be only one, but just in case ...}
while AFilename.StartsWith('/') or AFilename.StartsWith('.') do
Delete(AFilename, 1, 1);
{Alternatively, one could just do:
AFilename := GeCurrentDir + AFilename;
or whatever the web-root directory is,
but that's not very secure}
{ If we find the file, serve it; if not, fawn about it}
if FileExists(AFilename) then begin
AResponse.Code := 200;
AResponse.Content := ReadFileToString(AFilename);
end else begin
AResponse.Code := 404;
AResponse.Content := 'Sorry, don''t have any "' + AFilename +'"';
end;
end;