Skip to content

fiction.serveCGI

Creates a static route and executes executable CGI file with specific environment variables on request

Terminal window
fiction.serveCGI "<file>" "<routeAlias?>" "<content type?>"
ArgumentDescriptionTypeRequired
$1File to executefiletrue
$2Use $2 instead of /<file> for route namestringfalse
$3Use custom content type instead of automatically defined onestringfalse
NameDescription
SERVER_SOFTWAREName and version of the software
REQUEST_METHODRequest method
REQUEST_PATHFull path of the request
FICTION_ROUTESame as REQUEST_PATH
REMOTE_ADDRIP address of client
SCRIPT_FILENAMEFull path of current executable
HTTP_USER_AGENTClient’s user agent
HTTP_COOKIEClient’s cookie for page, if any
CONTENT_LENGTHPOST data length, if any
HTTPStrue if HTTPS is enabled, otherwise false

By HTTP standarts, valid CGI response is required. CGI scripts are required to send newline (\n) as delimeter for headers and response data, e.g.:

Content-Type: text/html
<html>
<p>Hello world!</p>
</html>

Fiction automatically manages response code and routing. If client sends POST, PATCH or PUT request, it’s content length is stored in $CONTENT_LENGTH and the content is passed to CGI