-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.cpp
48 lines (32 loc) · 1.05 KB
/
server.cpp
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
48
#include <bete/runtime.hxx>
#include <bete/websocket/server.hxx>
#include <bete/remote_observable.hxx>
#include <bete/server.hxx>
#include "datamodel.hxx"
using namespace std::string_literals;
struct app_scope {
bete::server rest;
bete::observable_server ws;
belle::vue::observable<datamodel_t> datamodel{};
void main() {
register_deep_observable(datamodel, "/datamodel", ws);
ws.async_listen(8888);
datamodel->benchmarks->push_back({"The first benchmark", 43, 43, 43});
rest.GET("/add", [&](bete::session&& session, std::string name, size_t min, size_t max, size_t avg) {
datamodel->benchmarks->push_back({name, min, max, avg});
session.response.write("Added : "s + name
+ "with min="s + std::to_string(min)
+ ", max="s + std::to_string(max)
+ ", avg="s + std::to_string(avg) + "."
);
});
rest.listen(8787);
}
};
static std::shared_ptr<app_scope> app_scope_;
int main() {
bete::runtime r{};
app_scope_ = std::make_shared<app_scope>();
app_scope_->main();
return 0;
}