forked from mohamed-lahrach/webserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
55 lines (49 loc) · 1.29 KB
/
Copy pathmain.cpp
File metadata and controls
55 lines (49 loc) · 1.29 KB
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
#include "Server_setup/server.hpp"
#include "config/Lexer.hpp"
#include "config/parser.hpp"
#include <vector>
#include <signal.h>
int main(int argc, char **argv)
{
signal(SIGPIPE, SIG_IGN);
if (argc != 2)
{
std::cerr << "Usage: " << argv[0] << " <config_file>" << std::endl;
std::cerr << "Example: " << argv[0] << " ./test_configs/default.conf" << std::endl;
return (1);
}
Lexer lexer(argv[1]);
std::vector<ServerContext> servers_config;
std::vector<Token> tokens = lexer.tokenizeAll();
std::cout << "-------------------------" << std::endl;
Parser parser(tokens);
try
{
parser.parse();
servers_config = parser.getServers();
std::cout << "Parsing completed successfully!" << std::endl;
std::cout << "Found " << servers_config.size() << " server configurations" << std::endl;
}
catch (const std::runtime_error &e)
{
std::cerr << e.what() << std::endl;
return 1;
}
Server server;
try
{
if (servers_config.empty())
{
std::cerr << "No server blocks found in config." << std::endl;
return 1;
}
server.init_data(servers_config);
server.run();
}
catch (const std::exception &e)
{
std::cerr << "Error: " << e.what() << std::endl;
return (-1);
}
return (0);
}