-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_simple_server.cpp
More file actions
47 lines (40 loc) · 1.15 KB
/
test_simple_server.cpp
File metadata and controls
47 lines (40 loc) · 1.15 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
44
45
46
47
/**
* Minimal test to debug server issues
*/
#include "src/cpp/http/server.h"
#include "src/cpp/http/request.h"
#include "src/cpp/http/response.h"
#include <iostream>
int main() {
// Create server config
HttpServer::Config config;
config.port = 8000;
config.host = "0.0.0.0";
config.enable_h1 = true;
config.enable_h2 = false;
// Create server
HttpServer server(config);
// Add single route
std::cout << "Adding route GET /\n";
int result = server.add_route("GET", "/",
[](HttpRequest* req, HttpResponse* res, const fasterapi::http::RouteParams& params) {
std::cout << "Handler called!\n";
res->status(HttpResponse::Status::OK)
.content_type("text/plain")
.text("Hello, World!")
.send();
}
);
if (result != 0) {
std::cerr << "Failed to add route: " << result << "\n";
return 1;
}
// Start server
std::cout << "Starting server on port 8000...\n";
result = server.start();
if (result != 0) {
std::cerr << "Failed to start server: " << result << "\n";
return 1;
}
return 0;
}