0

I am trying to display an html page in mongoose server I tried using the below code which is not working can any one tell me what is the issue in that code.

#include <stdio.h>
#include <string.h>
#include "mongoose/mongoose.h"

static int begin_request_handler(struct mg_connection *conn) {
    const struct mg_request_info *request_info = mg_get_request_info(conn);
    static const char *login_url = "/index.html";
    mg_printf(conn, "HTTP/1.1 200 OK\r\n"
            "Content-Type: text/html\r\n"
            "Location: %s\r\n\r\n", login_url);
    return 1;
}

int main(void) {
    struct mg_context *ctx;
    struct mg_callbacks callbacks;
    const char *options[] = { "listening_ports", "8080", NULL };
    memset(&callbacks, 0, sizeof(callbacks));
    callbacks.begin_request = begin_request_handler;
    ctx = mg_start(&callbacks, NULL, options);
    getchar();
    mg_stop(ctx);
    return 0;
}
JohnnyHK
  • 305,182
  • 66
  • 621
  • 471
Kathick
  • 1,395
  • 5
  • 19
  • 30

1 Answers1

0

What are you trying to accomplish? In the options[] add a "document_root" (you always need a document_root in your options for mongoose), place your index.html in that directory, and remove the callbacks from mg_start. And mongoose will serve your index.html automatically.

jmucchiello
  • 18,754
  • 7
  • 41
  • 61