-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
43 lines (40 loc) · 1.18 KB
/
main.cpp
File metadata and controls
43 lines (40 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "ArgsParser.h"
#include "HttpMessage.h"
#include "HttpServer.h"
#include "RouteMap.h"
#include "SocketServer.h"
#include "jjson.hpp"
#include <iostream>
int main(int argc, char* argv[])
{
ArgsParser parser(argv[0]);
parser.AddOption('f', "config_file", "location of configuration file in .json format", true);
parser.AddOption('p', "port", "Tcp port to accept server connections", false);
parser.AddOption('t', "timeout", "Time out of server to close connection", false);
parser.Parse(argc, argv);
auto argument_map = parser.GetArgs();
auto file_name = argument_map['f'];
auto port = 0;
if (argument_map.find('p') != argument_map.end())
{
port = std::stoi(argument_map['p']);
}
auto timeout = 0;
if (argument_map.find('t') != argument_map.end())
{
timeout = std::stoi(argument_map['t']);
}
auto server = HttpServer();
auto get_api = [](HttpRequest&& request) -> HttpResponse
{
auto api_object = jjson::Object();
api_object["running"] = true;
HttpResponse response;
response.SetStatusCode(200);
response.SetHeader("content-type", "application/json");
response.SetBody(api_object);
return response;
};
server.Get("/api", get_api);
server.Init(file_name);
}