You can use
rvk's code without problems (I just tested it).
Just add some code to the
OnRequest method (in the main form) to handle returning the files from wherever you put them.
This is an extremely simple example which just tries to find the file(s) in the current directory, but nothing prevents you from serving them from anywhere else. In that case, though, you will have to deal with the paths in the request by yourself--but that's not cumbersome or difficult:
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;
With my test program running ((it incorporates the example code) if, for example, I ask in the browser for:
http://localhost:8081/unit1.pasit shows the source for the unit.