-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
62 lines (50 loc) · 1.68 KB
/
main.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// ________ ____ __ __ __
// / ____/ /_ ____ _____ _______ __/ __ \____ / /_ __/ /_ ___ ____/ /________ _
// / / / __ \/ __ `/ __ \/ ___/ / / / /_/ / __ \/ / / / / __ \/ _ \/ __ / ___/ __ `/
// / /___/ / / / /_/ / / / / /__/ /_/ / ____/ /_/ / / /_/ / / / / __/ /_/ / / / /_/ /
// \____/_/ /_/\__,_/_/ /_/\___/\__, /_/ \____/_/\__, /_/ /_/\___/\__,_/_/ \__,_/
// /____/ /____/
//
// Copyright © 2017 D.E. Goodman-Wilson
//
#include <iostream>
#include <luna/luna.h>
#include <nlohmann/json.hpp>
#include "logger.hpp"
#include "controllers/chancypolyhedra_controller.hpp"
int main()
{
// set up the loggers
luna::set_access_logger(access_logger);
luna::set_error_logger(error_logger);
// determine which port to run on, default to 8080
auto port = 8080;
if (auto port_str = std::getenv("PORT"))
{
try
{
port = std::atoi(port_str);
}
catch (const std::invalid_argument &e)
{
error_logger(luna::log_level::FATAL, "Invalid port specified in env $PORT.");
return 1;
}
catch (const std::out_of_range &e)
{
error_logger(luna::log_level::FATAL, "Port specified in env $PORT is too large.");
return 1;
}
}
// create server
luna::server server;
// add endpoints
auto api = server.create_router("/v1");
// Here is an endpoint handled by a controller class, in controllers/chancypolyhedra_controller.hpp
chancypolyhedra_controller.add(api);
if(!server.start(port))
{
return 1;
}
return 0;
}