Recent

Author Topic: [SOLVED] Help for the start of HTTPServer  (Read 307 times)

egsuh

  • Sr. Member
  • ****
  • Posts: 436
[SOLVED] Help for the start of HTTPServer
« on: September 16, 2020, 01:05:31 pm »
Hi,
I can write CGI or FCGI web server, but not the simple(?) HTTPServer.  I cannot make it start.
Please see my following example.

Code: Pascal  [Select][+][-]
  1. program HTTPServer;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   Sysutils, fpwebfile,  fphttpapp;
  7.  
  8. begin
  9.   RegisterFileLocation('Demos','C:\inetpub\wwwroot\Demos');
  10.   Application.Title:='httpproject1';
  11.   Application.Port:=8040;
  12.   Application.Initialize;
  13.   Application.Run;
  14. end.

No other units.

I run this, open a browser, and type "http://localhost:8040/demos/abc.html".
What I get is an error message (attached file).

This is my first time to try HTTPServer. Please advise me what I'm doing wrong.

Windows 10, and IIS is running. So, localhost/demos/abc.html works fine. 
« Last Edit: September 17, 2020, 05:07:27 am by egsuh »

PascalDragon

  • Hero Member
  • *****
  • Posts: 2138
  • Compiler Developer
Re: Help for the start of HTTPServer
« Reply #1 on: September 16, 2020, 01:32:28 pm »
You're probably falling victim to this problem which results in the simple RegisterFileLocation not working Windows.

It should be possible to use the following “hack” instead (requires 3.2.0):

Code: Pascal  [Select][+][-]
  1. begin
  2.   TSimpleFileModule.BaseDir := 'C:\inetpub\wwwroot\Demos';
  3.   HTTPRouter.RegisterRoute('/Demos/*', TSimpleFileModule.HandleSimpleFileRequest);
  4.   // ...
  5. end.

Or if your program is started from C:\ as well you can try this:

Code: Pascal  [Select][+][-]
  1. RegisterFileLocation('/Demos/*','/inetpub\wwwroot\Demos');

This is a so called drive absolute path and uses the drive of the current working directory as root (this is done by Windows). The ‘/’ instead of ‘\’ is necessary because of the code in RegisterFileLocation, otherwise ‘\’ would be okay.

egsuh

  • Sr. Member
  • ****
  • Posts: 436
Re: Help for the start of HTTPServer
« Reply #2 on: September 16, 2020, 02:21:14 pm »
Quote
simple RegisterFileLocation not working Windows.


Ah... problem with Windows file definition.  My current FPC version is 3.0.8. I'll upgrade it and try your first hack. Thank you very much.

PascalDragon

  • Hero Member
  • *****
  • Posts: 2138
  • Compiler Developer
Re: Help for the start of HTTPServer
« Reply #3 on: September 17, 2020, 09:28:27 am »
Ah... problem with Windows file definition.  My current FPC version is 3.0.8. I'll upgrade it and try your first hack. Thank you very much.

I take it you either mean FPC 3.0.4 or Lazarus 2.0.8? ;)

egsuh

  • Sr. Member
  • ****
  • Posts: 436
Re: [SOLVED] Help for the start of HTTPServer
« Reply #4 on: September 17, 2020, 11:59:12 am »
Quote
I take it you either mean FPC 3.0.4 or Lazarus 2.0.8?

You are right. Sorry for the confusion.

 

TinyPortal © 2005-2018