-// this function return either Index.htlm or a redirect to /#!route to make angular happy
-STATIC int checkHTML5(struct MHD_Connection *connection, AFB_session *session, const char* url) {
-
- int fd;
- int ret;
- struct MHD_Response *response;
- char filepath [512];
-
- // if requesting '/' serve index.html
- if (strlen (url) == 0) {
- strncpy(filepath, session->config->rootdir, sizeof (filepath));
- strncat(filepath, "/index.html", sizeof (filepath));
- // try to open file and get its size
- if (-1 == (fd = open(filepath, O_RDONLY))) {
- fprintf(stderr, "Fail to open file: [%s] error:%s\n", filepath, strerror(errno));
- // Nothing respond to this request Files, API, Angular Base
- const char *errorstr = "<html><body>Alsa-Json-Gateway Unknown or Not readable file</body></html>";
- response = MHD_create_response_from_buffer(strlen(errorstr),(void *)errorstr, MHD_RESPMEM_PERSISTENT);
- ret = MHD_queue_response(connection, MHD_HTTP_INTERNAL_SERVER_ERROR, response);
- ret = MHD_YES;
- return (FAILED);
- } else {
- ret = servFile (connection, session, url, filepath, fd);
- return ret;
- }
- }
-
- // we are facing a internal route within the HTML5 OnePageApp let's redirect ex: /myapp/#!user/login
- strncpy(filepath, session->config->rootbase, sizeof (filepath));
- strncat(filepath, "#!", sizeof (filepath));
- strncat(filepath, url, sizeof (filepath));
- response = MHD_create_response_from_buffer(session->config->html5.len,(void *)session->config->html5.msg, MHD_RESPMEM_PERSISTENT);
- MHD_add_response_header (response, "Location", "http://somesite.com/page.html");
- MHD_queue_response (connection, MHD_HTTP_OK, response);
-}
-