AROS World Exec
Support => Free Pascal => Topic started 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.
-
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.
-
Super basic webserver code for proof of concept. I just used the Lazarus bundled fphttpserver stuff framework
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