mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-12-19 19:20:13 +00:00
redo it with mongoose
add all previous POC api endpoints
This commit is contained in:
@@ -1,36 +1,23 @@
|
||||
#ifndef INCLUDED_CHATWEBAPI_LINUX
|
||||
#define INCLUDED_CHATWEBAPI_LINUX
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
#ifndef INCLUDED_CHATWEBAPI
|
||||
#define INCLUDED_CHATWEBAPI
|
||||
|
||||
#include "mongoose.h"
|
||||
#include "json_fwd.hpp"
|
||||
#include "GeneralUtils.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
class ChatWebAPI {
|
||||
public:
|
||||
ChatWebAPI(std::string ip_address, int port);
|
||||
ChatWebAPI();
|
||||
~ChatWebAPI();
|
||||
void HandleRequest();
|
||||
|
||||
void ReceiveRequests();
|
||||
private:
|
||||
std::string m_ip_address;
|
||||
int m_port;
|
||||
int m_socket;
|
||||
int m_new_socket;
|
||||
long m_incomingMessage;
|
||||
struct sockaddr_in m_socketAddress;
|
||||
unsigned int m_socketAddress_len;
|
||||
std::string m_serverMessage;
|
||||
struct timeval m_tv;
|
||||
fd_set fdread;
|
||||
|
||||
std::string buildResponse(int status, std::string input);
|
||||
void sendResponse(int status, std::string input);
|
||||
void HandleAction(json data);
|
||||
struct mg_mgr mgr;
|
||||
static void HandleRequests(struct mg_connection *c, int ev, void *ev_data);
|
||||
inline static const std::string root_path = "/api/v1/";
|
||||
inline static const char * json_content_type = "Content-Type: application/json\r\n";
|
||||
static std::optional<json> ParseJSON(char * data);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user