Add correctly shutting down server and stopping threads
This commit is contained in:
22
main.cpp
22
main.cpp
@@ -1,18 +1,33 @@
|
||||
#include "http.hpp"
|
||||
#include "router.hpp"
|
||||
#include <csignal>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
using namespace http;
|
||||
|
||||
void HelloWorld(Request req, Response *res) {
|
||||
void hello_world(Request req, Response *res) {
|
||||
res->set_payload("Hello World!");
|
||||
res->set_content_type("text/plain");
|
||||
}
|
||||
|
||||
static Router router(8181);
|
||||
|
||||
void quit(int s) {
|
||||
router.stop();
|
||||
std::cout << "Stopping Server" << std::endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
Router router(8181);
|
||||
struct sigaction sig_int_handler;
|
||||
sig_int_handler.sa_handler = quit;
|
||||
sigemptyset(&sig_int_handler.sa_mask);
|
||||
sig_int_handler.sa_flags = 0;
|
||||
|
||||
sigaction(SIGINT, &sig_int_handler, nullptr);
|
||||
|
||||
// Allow all Methods
|
||||
router.handle("GET /helloWorld", HelloWorld);
|
||||
router.handle("GET /helloWorld", hello_world);
|
||||
router.handle("GET /healthz", [](Request req, Response *res) {
|
||||
res->set_status_code(StatusCode::OK);
|
||||
res->set_payload(std::vector<std::byte>());
|
||||
@@ -38,6 +53,7 @@ int main() {
|
||||
res->set_content_type("text/plain");
|
||||
});
|
||||
|
||||
std::cout << "Starting Server" << std::endl;
|
||||
router.start();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user