SpriteHTTPD - embedded HTTP server with read-only filesystem and templating, originally developed for ESP8266, now stand-alone and POSIX compatible.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
spritehttpd/main.c

58 lines
1.1 KiB

#include <stdio.h>
#include "httpd.h"
#include "httpd-utils.h"
#include "httpdespfs.h"
#include <httpd.h>
#include <cgiwebsocket.h>
#include <httpdespfs.h>
#include <auth.h>
#include "logging.h"
/** "About" page */
httpd_cgi_state tplIndex(HttpdConnData *connData, char *token, void **arg)
{
if (token == NULL) { return HTTPD_CGI_DONE; }
else if (streq(token, "date")) {
tplSend(connData, __DATE__, -1);
} else if (streq(token, "time")) {
tplSend(connData, __TIME__, -1);
} else if (streq(token, "vers_httpd")) {
tplSend(connData, httpdGetVersion(), -1);
}
return HTTPD_CGI_DONE;
}
/**
* Application routes
*/
const HttpdBuiltInUrl routes[] = {
// TODO password lock ...
// --- Web pages ---
ROUTE_TPL_FILE("/", tplIndex, "/index.tpl"),
ROUTE_FILESYSTEM(),
ROUTE_END(),
};
int main()
{
printf("Hello, World!\n");
struct httpd_options opts = {
.port = 80,
};
httpd_thread_handle_t *handle = httpdInit(routes, &opts);
httpdSetName("ServerName");
httpdJoin(handle);
return 0;
}