summaryrefslogtreecommitdiff
path: root/src/server.cpp
blob: 3efb51db8a6ca1da25b175cf6433e6bbf2d9594e (plain)
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
31
32
33
34
35
#include <iostream>
#include <string>
#include "mongoose.h"
#include "apiHandler.h"

using namespace std;

int event_handler(struct mg_connection *conn, enum mg_event ev) {
	apiHandler MyApiHandler(conn);

    switch (ev) {
        case MG_AUTH: return MG_TRUE;
        case MG_REQUEST: return MyApiHandler.processRequest();
        default: return MG_FALSE;
    }
}

int main(int argc, char **argv) {
    string server_port = "8080";

    struct mg_server *server = mg_create_server(NULL, event_handler);

    mg_set_option(server, "document_root", "./www/");
    mg_set_option(server, "enable_directory_listing", "no");
    mg_set_option(server, "listening_port", server_port.c_str());

    cout<<"Staring server on port "<<server_port<<"."<<endl;
    while (true) {
        mg_poll_server(server, 1000);
    }

    mg_destroy_server(&server);
    
    return 0;
}