summaryrefslogtreecommitdiffhomepage
path: root/source/app.d
blob: 11155241fa16d06324440cc6d9358c35d7eb5f22 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import brpaste.web;

import vibe.d;

shared static this() {
    // HTTP settings
    auto settings = new HTTPServerSettings;
    settings.port = 8080;
    settings.bindAddresses = [];

    readOption("bind|b", &settings.bindAddresses, "Sets the addresses to bind to [127.0.0.1 ::1]");
    readOption("port|p", &settings.port, "Sets the port to listen on [8080]");
    if(settings.bindAddresses.empty) settings.bindAddresses = [ "127.0.0.1", "::1" ];

    // setup router
    auto router = new URLRouter;

    router.match(HTTPMethod.REPORT, "/health", &health);
    router.get("/health", &health);

    router.get("/", staticTemplate!"index.dt");

    router.post("/", &post);
    router.put("/:id", &put);

    router.get("/:id", &idLng);
    router.get("/raw/:id", &idRaw);

    listenHTTP(settings, router);
}