diff options
Diffstat (limited to 'src/server.cpp')
-rw-r--r-- | src/server.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/server.cpp b/src/server.cpp new file mode 100644 index 0000000..3efb51d --- /dev/null +++ b/src/server.cpp @@ -0,0 +1,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; +} |