How to setup D language with Apache httpd cgi?

Andre Pany andre at s-e-a-p.de
Wed Jul 31 20:16:40 UTC 2019


On Wednesday, 31 July 2019 at 17:04:58 UTC, BoQsc wrote:
> However I tried to add options (--single) to the dub shebang 
> and apache now throwing: "bad header error"
>
> Without "--single" option seems to work.
>
>
>>#!/usr/bin/env -vS dub --single
>>/+ dub.sdl:
>>    name "application"
>>    dependency "arsd-official:dom" version="4.0.2"
>>+/
>>import std.stdio;
>>import arsd.dom;
>>void main()
>>{
>>    writeln(`Content-type: text/html`);
>>    writeln(``);
>>    writeln(`test`);
>>
>>}
>
>
>
>>split -S:  'dub --single'
>> into:    'dub'
>>     &    '--single'
>>executing: dub
>>   arg[0]= 'dub'
>>   arg[1]= '--single'
>>   arg[2]= '/usr/lib/cgi-bin/example.d'
>>[Wed Jul 31 19:57:56.892522 2019] [cgid:error] [pid 833:tid 
>>140583783876352] [client >127.0.0.1:43598] malformed header 
>>from script 'example.d': Bad header: Performing "debug" >build 
>>using

As already pointed out, as starting point you could compile the 
application e.g. within folder /tmp and then copy the executable 
to cgi-bin folder.
Please make sure it has executable flag.

dub build --single hello.d

The application could look like this:
#!/usr/bin/env dub

/+ dub.sdl:
     name "application"
     dependency "arsd-official:cgi" version="4.0.2"
     subConfiguration "arsd-official:cgi" "cgi"
+/
import arsd.cgi;

void hello(Cgi cgi) {                                             
                      cgi.setResponseContentType("text/plain");

     if("name" in cgi.get)
         cgi.write("Hello, " ~ cgi.get["name"]);
     else
         cgi.write("Hello, world!");
  }

mixin GenericMain!hello;

Kind regards
Andre


More information about the Digitalmars-d-learn mailing list