reserved 1.0.5
A minimal library to run your D application on your webserver using scgi
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
Reserved
A scgi client for D programming language. Doc: dpldocs
The simple way
#!/usr/bin/env dub
/+ dub.sdl:
name "awesome_d_webservice"
dependency "reserved" version="1.0.0"
+/
import reserved;
import std.stdio;
@ReservedResponse
private void response(Request req, Output output)
{
output ~= "Hello ";
if ("name" in req.get)
output ~= req.get["name"];
else
output ~= "World";
}
mixin Reserved!"awesome_d_webservice";
Starting this example will create a socket named `/tmp/run/awesome_d_webservice/listener.0.sock
`.
If another process is still running on the same socket it will be (gracefully) killed.
Configure the server
To make nginx (for example) working with reserved just add these lines on its config file (on ubuntu: `/etc/nginx/sites-available/default
`) and restart nginx:
location / {
include scgi_params;
scgi_pass unix:/tmp/run/awesome_d_webservice/listener.0.sock;
}
Pay attention to sock file permission. Both your application and nginx must have permission to read/write that file. The easy way is to run both with the same user.
Once the server is running, just browse to http://localhost/?name=D
Init function
If you need to call a one-time-init function, you can annotate it with `@ReservedInit
`.
Its signature must be one of these:
bool init()
// will be called using main() args
bool init(string[] args)
It musts return true on success.
Multiple responders
If you want to run multiple parallel responders, just use `-i
options on command line. For example
./your_app -i 3
will create a socket named
/tmp/run/awesome_d_webservice/listener.3.sock
` and/or will kill any process running on it.
- 1.0.5 released 5 years ago
- 2night/Reserved
- MIT
- Copyright © 2017-2018, 2night.it
- Authors:
- Dependencies:
- none
- Versions:
-
1.0.5 2019-Nov-08 1.0.4 2019-Jun-05 1.0.3 2019-May-17 1.0.2 2019-Mar-21 1.0.1 2018-Jul-05 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
0 downloads this month
-
536 downloads total
-
- Score:
- 1.0
- Short URL:
- reserved.dub.pm