2023-09-16 16:29:03 +02:00
|
|
|
#include "VWeb-1.0/VWeb.h"
|
2022-08-23 14:13:21 +02:00
|
|
|
|
2022-11-09 14:34:20 +01:00
|
|
|
class MyCompleteController : public VWeb::Route {
|
|
|
|
public:
|
|
|
|
bool Get(const VWeb::Request&, VWeb::Response& response) {
|
|
|
|
response << "MyCompleteController: GET";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool Post(const VWeb::Request&, VWeb::Response& response) {
|
|
|
|
response << "MyCompleteController: POST";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsAllowed(const VWeb::Request& request) {
|
|
|
|
return request.HasHeader("Auth");
|
|
|
|
}
|
|
|
|
};
|
2022-08-23 16:40:57 +02:00
|
|
|
bool Ping(const VWeb::Request&, VWeb::Response& response) {
|
|
|
|
response << "Pong";
|
|
|
|
return true;
|
|
|
|
}
|
2022-08-23 14:13:21 +02:00
|
|
|
int main() {
|
2022-08-23 16:40:57 +02:00
|
|
|
using namespace VWeb;
|
2022-08-23 14:13:21 +02:00
|
|
|
VWeb::Server server;
|
2022-08-23 16:40:57 +02:00
|
|
|
auto& router = server.GetRouter();
|
2023-09-02 14:17:56 +02:00
|
|
|
// For debugging and profiling more than 1 thread can be hard.
|
|
|
|
server.GetServerConfig()->WorkerThreads = 1;
|
2022-08-23 16:40:57 +02:00
|
|
|
router->Get("/test", [](const Request&, Response& response) {
|
|
|
|
response << "NICE";
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
router->Get("/ping", &Ping);
|
2022-08-23 14:13:21 +02:00
|
|
|
server.Start();
|
|
|
|
server.Join();
|
|
|
|
return 0;
|
|
|
|
}
|