add remote app ('rest_interface.c')

This commit is contained in:
btsimonh
2022-02-07 22:29:39 +00:00
parent 8175b353d3
commit 602b82b943
2 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,62 @@
#include "../new_common.h"
#include "../logging/logging.h"
#include "../httpserver/new_http.h"
#include "str_pub.h"
static int http_rest_get(http_request_t *request);
static int http_rest_post(http_request_t *request);
static int http_rest_app(http_request_t *request);
void init_rest(){
HTTP_RegisterCallback( "/api", HTTP_GET, http_rest_get);
HTTP_RegisterCallback( "/api", HTTP_POST, http_rest_post);
HTTP_RegisterCallback( "/app", HTTP_GET, http_rest_app);
}
const char *apppage1 =
"<!DOCTYPE html>"
"<html>"
" <head>"
" <script>"
" var root = '";
const char * apppage2 = "';"
" var device = 'http://";
const char * apppage3 = "';"
" </script>"
" <script src=\"";
const char * apppage4 = "/startup.js\"></script>"
" </head>"
"<body>"
"</body>"
"</html>";
static int http_rest_app(http_request_t *request){
http_setup(request, httpMimeTypeHTML);
//char *webhost = "http://raspberrypi:1880";//CFG_GetWebRoot();
char *webhost = "https://btsimonh.github.io/testwebpages/";
char *ourip = "192.168.1.176"; //CFG_GetOurIP();
if (webhost && ourip){
poststr(request, apppage1);
poststr(request, webhost);
poststr(request, apppage2);
poststr(request, ourip);
poststr(request, apppage3);
poststr(request, webhost);
poststr(request, apppage4);
} else {
poststr(request,htmlHeader);
poststr(request,htmlReturnToMenu);
poststr(request,"no APP available<br/>");
}
poststr(request,NULL);
return 0;
}
static int http_rest_get(http_request_t *request){
return 0;
}
static int http_rest_post(http_request_t *request){
return 0;
}