-// 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;
- AFB_staticfile staticfile;
-
- // Any URL prefixed with /rootbase is served with index.html ex: /opa,/opa/,/opa/#!xxxxxx
- if ( url[0] == '\0' || url[1] == '\0' || url[1] == '#') {
- strncpy(staticfile.path, session->config->rootdir, sizeof (staticfile.path));
- strncat(staticfile.path, "/index.html", sizeof (staticfile.path));
- // try to open file and get its size
- if (-1 == (staticfile.fd = open(staticfile.path, O_RDONLY))) {
- fprintf(stderr, "Fail to open file: [%s] error:%s\n", staticfile.path, strerror(errno));
- // Nothing respond to this request Files, API, Angular Base
- const char *errorstr = "<html><body>Application Framework OPA/index.html Not found</body></html>";
- response = MHD_create_response_from_buffer(strlen(errorstr),(void *)errorstr, MHD_RESPMEM_PERSISTENT);
- MHD_queue_response(connection, MHD_HTTP_INTERNAL_SERVER_ERROR, response);
- return (MHD_YES);
- } else {
- ret = servFile (connection, session, url, &staticfile);
- return ret;
- }
- }
-
- // Url match /opa/xxxx but not /opa#!xxxx we redirect the URL to /opa#!/xxxx to force index.html reload
- strncpy(staticfile.path, session->config->rootbase, sizeof (staticfile.path));
- strncat(staticfile.path, "#!", sizeof (staticfile.path));
- strncat(staticfile.path, url, sizeof (staticfile.path));
- response = MHD_create_response_from_buffer(0,"", MHD_RESPMEM_PERSISTENT);
- MHD_add_response_header (response, "Location", staticfile.path);
- MHD_queue_response (connection, MHD_HTTP_MOVED_PERMANENTLY, response);
- if (verbose) fprintf (stderr,"checkHTML5 redirect to [%s]\n",staticfile.path);
- return (MHD_YES);
-}
-