Shelly skripta
This commit is contained in:
@@ -4,17 +4,16 @@
|
||||
#include <stdio.h>
|
||||
#include <jansson.h>
|
||||
|
||||
static const char *s_http_port = "8001";
|
||||
static const char *s_http_port = "127.0.0.1:8001";
|
||||
static const char *s_root_dir = "."; // Serve current directory
|
||||
|
||||
static void handle_get(struct mg_connection *c, struct mg_http_message *hm) {
|
||||
char query[256] = {0};
|
||||
char *response;
|
||||
|
||||
// Parse query parameter 'q'
|
||||
mg_http_get_var(&hm->query, "q", query, sizeof(query));
|
||||
|
||||
response = db_query(query);
|
||||
char *response = db_query(query);
|
||||
|
||||
mg_http_reply(c, 200, "Content-Type: application/json\r\n", "%s", response);
|
||||
|
||||
@@ -62,16 +61,16 @@ static void handle_post(struct mg_connection *c, struct mg_http_message *hm) {
|
||||
}
|
||||
|
||||
static void handle_api_call(struct mg_connection *c, struct mg_http_message *hm) {
|
||||
if (mg_casecmp(&hm->method, "GET") == 0) {
|
||||
if (mg_strcasecmp(hm->method, mg_str("GET")) == 0) {
|
||||
handle_get(c, hm);
|
||||
} else if (mg_casecmp(&hm->method, "POST") == 0) {
|
||||
} else if (mg_strcasecmp(hm->method, mg_str("POST")) == 0) {
|
||||
handle_post(c, hm);
|
||||
} else {
|
||||
mg_http_reply(c, 405, "Content-Type: text/plain\r\n", "Method Not Allowed");
|
||||
}
|
||||
}
|
||||
|
||||
static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
||||
static void fn(struct mg_connection *c, int ev, void *ev_data) {
|
||||
if (ev == MG_EV_HTTP_MSG) {
|
||||
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user