2015-09-08 19:49:03 +08:00
|
|
|
// Copyright (c) 2015 Cesanta Software Limited
|
|
|
|
// All rights reserved
|
|
|
|
|
|
|
|
#include "mongoose.h"
|
|
|
|
|
|
|
|
static const char *s_http_port = "8000";
|
|
|
|
static struct mg_serve_http_opts s_http_server_opts;
|
|
|
|
|
|
|
|
static void ev_handler(struct mg_connection *nc, int ev, void *p) {
|
2015-09-19 19:38:46 +08:00
|
|
|
if (ev == MG_EV_HTTP_REQUEST) {
|
2015-12-03 00:53:04 +08:00
|
|
|
mg_serve_http(nc, (struct http_message *) p, s_http_server_opts);
|
2015-09-08 19:49:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void) {
|
|
|
|
struct mg_mgr mgr;
|
|
|
|
struct mg_connection *nc;
|
|
|
|
|
|
|
|
mg_mgr_init(&mgr, NULL);
|
|
|
|
nc = mg_bind(&mgr, s_http_port, ev_handler);
|
|
|
|
|
|
|
|
// Set up HTTP server parameters
|
|
|
|
mg_set_protocol_http_websocket(nc);
|
2016-06-09 19:13:19 +08:00
|
|
|
s_http_server_opts.document_root = "."; // Serve current directory
|
2015-12-08 04:18:06 +08:00
|
|
|
s_http_server_opts.dav_document_root = "."; // Allow access via WebDav
|
2015-09-08 19:49:03 +08:00
|
|
|
s_http_server_opts.enable_directory_listing = "yes";
|
|
|
|
|
|
|
|
printf("Starting web server on port %s\n", s_http_port);
|
|
|
|
for (;;) {
|
|
|
|
mg_mgr_poll(&mgr, 1000);
|
|
|
|
}
|
|
|
|
mg_mgr_free(&mgr);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|