after playing around with some basics I'd like to serve a directory from spiffs with mongoose.
I started with an example from mongoose.
Code: Select all
if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/api/config/get")) {
ESP_LOGD(LOG_TAG, "api/config/get");
char *s = stringify_config(&s_config);
mg_printf(c, "HTTP/1.1 200 OK\r\nContent-Length: %d\r\n\r\n%s\n",
(int) strlen(s) + 1, s);
free(s);
} else if (mg_http_match_uri(hm, "/api/config/set")) {
ESP_LOGD(LOG_TAG, "/api/config/set");
if (update_config(hm, &s_config)) notify_config_change((struct mg_mgr*) fn_data);
mg_printf(c, "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
} else if (mg_http_match_uri(hm, "/api/config/watch")) {
ESP_LOGD(LOG_TAG, "/api/config/watch");
c->label[0] = 'W'; // Mark ourselves as a config watcher
mg_printf(c, "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n");
} else {
ESP_LOGD(LOG_TAG, "else");
struct mg_http_serve_opts opts = {.root_dir = "/www"};
//mg_http_serve_file(c, (struct mg_http_message*) ev_data, "/www/index.html", "text/html", "AA: bb\r\nCC: dd\r\n");
mg_http_serve_dir(c, (struct mg_http_message*) ev_data, &opts);
}
}
To be sure the files are available I did the following:
Code: Select all
FileSystem *file = new FileSystem();
std::vector<File> test = file->getDirectoryContents("/www");
for(int i = 0; i < test.size(); i++) {
cout << test[i].getName();
}
I tried to do the same with mg_http_serve_file but it didn't work, too.
Whats going wrong and why can't mongoose find the files to server? Can someone help me?
Kind Regards