-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
44 lines (38 loc) · 1.22 KB
/
main.cpp
File metadata and controls
44 lines (38 loc) · 1.22 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 <iostream>
#include "core.hpp"
#include "http/http.hpp"
using namespace nodecxx;
//int main()
//{
// auto server = server::createServer([](auto& socket){
// std::cout << "Opened a connection" << std::endl;
// socket.on(error, [&socket](const boost::system::error_code& ec) {
// std::cerr << "Got an error:" << ec.message() << std::endl;
// socket.close();
// });
// socket.on(data, [&socket](const std::vector<char>& data) {
// auto str = std::string(data.begin(), data.end());
// std::cout << str;
// if (str == "close\r\n")
// socket.end(std::vector<char>(data.begin(), data.end()));
// else
// socket.write(std::vector<char>(data.begin(), data.end()));
// });
// });
// server.listen("8713", "localhost");
// run();
//}
int main()
{
HttpServer server;
server.on(request, [](auto& req, auto& resp) {
resp.setHeader("Content-Type", "application/json");
resp.end(Json(Json::object {
{ "key1", "value1" },
{ "key2", "value2" },
{ "arr", Json::array {12.5, 2.0} }
}));
});
server.listen("8713", "localhost");
run();
}