Webserver running on AROS

MarcusF · 213

MarcusF

  • Newbie
  • *
    • Posts: 38
    • Karma: +11/-0
on: July 22, 2022, 07:47:33 PM
Webserver running on AROS in a VM, serving a website viewed on the host machine.



magorium

  • Moderator
  • Legendary Member
  • *****
    • Posts: 505
    • Karma: +55/-0
  • Convicted non contributor
Reply #1 on: July 22, 2022, 10: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.


MarcusF

  • Newbie
  • *
    • Posts: 38
    • Karma: +11/-0
Reply #2 on: July 22, 2022, 10: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