Skip to content

Commit

Permalink
server draft
Browse files Browse the repository at this point in the history
  • Loading branch information
noahrav committed Dec 23, 2023
1 parent 3af737e commit ac43595
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ _deps

.idea/
build/
cmake-build-debug/
cmake-build-debug/
cmake-build-debug-wsl/
30 changes: 29 additions & 1 deletion src/api/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,36 @@ class CUSubmitterHandler : public Http::Handler {
void onRequest(const Http::Request& request, Http::ResponseWriter response) override {
logRequest(request);

response.send(Http::Code::Ok, "CU Submitter backend is reponding\n");
if (request.resource() == "/" && request.method() == Http::Method::Get) {
response.send(Http::Code::Ok, "CU Submitter backend is reponding\n");
} else {
response.send(Http::Code::Not_Found);
}
}
};

class CUSubmitterService {
public:
explicit CUSubmitterService(Address addr)
: server(std::make_shared<Http::Endpoint>(addr)) {}

void init(size_t thr = 2) {
auto opts = Http::Endpoint::options().threads(static_cast<int>(thr));

server->init(opts);
server->setHandler(Http::make_handler<CUSubmitterHandler>());
}

void start() {
server->serve();
}

void shutdown() {
server->shutdown();
}

private:
std::shared_ptr<Http::Endpoint> server;
};

#endif //CU_SUBMITTER_API_H
8 changes: 3 additions & 5 deletions src/cu_submitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,8 @@ int main(int argc, char* argv[])

Address addr(Ipv4::any(), Port(stoi(port)));

auto opts = Http::Endpoint::options().threads(1);
Http::Endpoint server(addr);
CUSubmitterService service(addr);
service.init();

server.init(opts);
server.setHandler(Http::make_handler<CUSubmitterHandler>());
server.serve();
service.start();
}

0 comments on commit ac43595

Please sign in to comment.