Recent

Author Topic: BrookHTTPServer www folder  (Read 625 times)

promisetom

  • New member
  • *
  • Posts: 7
BrookHTTPServer www folder
« on: April 23, 2021, 02:21:22 am »
Hi All,
I am building a Brook HttpServer with SSE and I would like to have the css and js files served from a local folder.
Where in the Brook framework do I add this location.
Thanks in advance
Tom

egsuh

  • Hero Member
  • *****
  • Posts: 740
Re: BrookHTTPServer www folder
« Reply #1 on: April 23, 2021, 07:33:28 am »
Aren't css and js files defined within HTML file?

PierceNg

  • Full Member
  • ***
  • Posts: 110
Re: BrookHTTPServer www folder
« Reply #2 on: April 23, 2021, 09:10:54 am »
Aren't css and js files defined within HTML file?

Yes. They usually exist as separate files on the server. From a web server (application) perspective, they also have to be served as static content when the web browser follows the references in the HTML file and requests for these CSS and JS files.

promisetom

  • New member
  • *
  • Posts: 7
Re: BrookHTTPServer www folder
« Reply #3 on: April 24, 2021, 01:15:08 am »
In a Delphi app using Overbyte ics they have a DocDir which relates to the www folder in Apache etc.
This is what I need.
Tom

promisetom

  • New member
  • *
  • Posts: 7
Re: BrookHTTPServer www folder
« Reply #4 on: April 26, 2021, 03:33:27 am »
Found this idea and it works well.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.OnRequest(Sender: TObject;
  2.   var ARequest: TFPHTTPConnectionRequest;
  3.   var AResponse: TFPHTTPConnectionResponse);
  4. var
  5.   AFilename: String;
  6. begin
  7.   AFilename := ARequest.URI;
  8.   {Get rid of the starting bars so we won't serve from '/'
  9.    Theres should be only one, but just in case ...}
  10.   while AFilename.StartsWith('/') or AFilename.StartsWith('.') do
  11.     Delete(AFilename, 1, 1);
  12.   {Alternatively, one could just do:
  13.     AFilename := GeCurrentDir + AFilename;
  14.   or whatever the web-root directory is,
  15.   but that's not very secure}
  16.  
  17.   { If we find the file, serve it; if not, fawn about it}
  18.   if FileExists(AFilename) then begin
  19.     AResponse.Code := 200;
  20.     AResponse.Content := ReadFileToString(AFilename);
  21.   end else begin
  22.     AResponse.Code := 404;
  23.     AResponse.Content := 'Sorry, don''t have any "' + AFilename +'"';
  24.   end;
  25. end;
  26.  

from here. https://forum.lazarus.freepascal.org/index.php/topic,36178.15.html

I will post a webserver demo soon.
Tom

 

TinyPortal © 2005-2018