Console deployment is the default and most straightforward way to run Horse applications. It creates a standalone executable that can run on Windows, Linux, and macOS, making it ideal for development, testing, and production environments.
Console is the default provider for Horse. You don’t need to set any conditional defines unless you’re targeting a specific platform.
// Default host (0.0.0.0) and custom portTHorse.Listen(8080);// Custom host and portTHorse.Listen(8080, '127.0.0.1');// With callbacksTHorse.Listen(9000, procedure begin Writeln('Server started successfully'); end, procedure begin Writeln('Server stopped'); end);
# Make executablechmod +x console# Run directly./console# Run in backgroundnohup ./console > output.log 2>&1 &# Run with specific port./console --port=8080
Console applications work perfectly in Docker containers:
FROM debian:stable-slimWORKDIR /app# Copy your compiled binaryCOPY console /app/# Make it executableRUN chmod +x /app/console# Expose portEXPOSE 9000# Run the applicationCMD ["/app/console"]
program MultiPort;uses Horse, System.SysUtils;begin // Configure for specific interface THorse.Host := '192.168.1.100'; THorse.Port := 8080; THorse.Get('/api/status', procedure(Req: THorseRequest; Res: THorseResponse) begin Res.Send('{"status": "running"}'); end); THorse.Listen( procedure begin Writeln(Format('API Server listening on %s:%d', [THorse.Host, THorse.Port])); Writeln('Press ENTER to stop'); Readln; end, procedure begin Writeln('Server stopped gracefully'); end);end.