mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-01 13:10:43 +00:00
Add MG_ARCH_RTX
This commit is contained in:
1 parent
86cd567968
commit
31ce219544
6 files changed
+73
-60
No files matched your search
+14
-7
@@ -362,22 +362,29 @@ int mg_send(struct mg_connection *c, const void *buf, size_t len) {
|
||||
|
||||
## Minimal HTTP server
|
||||
|
||||
This example is a simple static HTTP server that serves current directory:
|
||||
This example is a simple HTTP server that serves both static and dynamic content:
|
||||
|
||||
```c
|
||||
#include "mongoose.h"
|
||||
|
||||
static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
||||
struct mg_http_serve_opts opts = {.root_dir = "."}; // Serve local dir
|
||||
if (ev == MG_EV_HTTP_MSG) mg_http_serve_dir(c, ev_data, &opts);
|
||||
if (ev == MG_EV_HTTP_MSG) {
|
||||
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
|
||||
if (mg_http_match_uri(hm, "/api/hello")) {
|
||||
mg_http_reply(c, 200, "", "%s\n", "hi"); // Serve dynamic content
|
||||
} else {
|
||||
struct mg_http_serve_opts opts = {.root_dir = "."}; // Serve
|
||||
mg_http_serve_dir(c, ev_data, &opts); // static content
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
struct mg_mgr mgr;
|
||||
mg_mgr_init(&mgr); // Init manager
|
||||
mg_http_listen(&mgr, "http://localhost:8000", fn, &mgr); // Setup listener
|
||||
for (;;) mg_mgr_poll(&mgr, 1000); // Event loop
|
||||
mg_mgr_free(&mgr); // Cleanup
|
||||
mg_mgr_init(&mgr); // Init manager
|
||||
mg_http_listen(&mgr, "http://0.0.0.0:8000", fn, &mgr); // Setup listener
|
||||
for (;;) mg_mgr_poll(&mgr, 1000); // Event loop
|
||||
mg_mgr_free(&mgr); // Cleanup
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
Reference in new issue
Block a user