AROS World Exec

Support => Free Pascal => Topic started by: MarcusF on July 22, 2022, 12:47:33 PM

Title: Webserver running on AROS
Post by: MarcusF on July 22, 2022, 12:47:33 PM
Webserver running on AROS in a VM, serving a website viewed on the host machine.
Title: Re: Webserver running on AROS
Post by: magorium on July 22, 2022, 03:27:00 PM
Nice Marcus.... what framework are you using there ?


There used to be a older version of this forum where i posted some Free Pascal/Lazarus examples, one of them being a small http-server form the FPC examples directory. Mind though that things weren't so integrated back then so it wasn't a simple re-compile but required a bit of work to get going.


Thanks to ALB42 and Chain-Q things have improved immensely in that regards.
Title: Re: Webserver running on AROS
Post by: MarcusF on July 22, 2022, 03:44:24 PM
Super basic webserver code for proof of concept. I just used the Lazarus bundled fphttpserver stuff framework

Code: [Select]
program AWebServer_lazarus;

{$mode objfpc}{$H+}

uses
  SysUtils, fphttpapp, httpdefs, httproute, fpwebfile;

procedure root_redirect(aRequest : TRequest; aResponse : TResponse);
begin
  aResponse.Code := 301;
  aResponse.SetCustomHeader('Location', 'site/index.html');
  aResponse.SendContent;
end;

begin
  Application.Port := 9080;

  RegisterFileLocation('site', 'site');
  MimeTypesFile := 'mime.types';

  HTTPRouter.RegisterRoute('/', @root_redirect);

  Application.Threaded := false;
  Application.Initialize;
  WriteLn('Server is ready on port ' + IntToStr(Application.Port));
  Application.Run;
end.

Have to copy mime.types into the same directory as the executable.

I plan to use this as a base for an auto-sync tool since I keep having issues with MarranoFTP