summaryrefslogtreecommitdiffhomepage
path: root/webserver.cpp
blob: 71829bb418241e39544cce4850cd222f350e26bf (plain)
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
#include "config.h"
#include "server.h"
#include "plugin.h"

#include <exception>
#include <iostream>
#include <string>

using namespace std::string_literals;

void usage()
{
 std::cout << "usage: webserver [-c <configuration-filename>]" << std::endl;
}

int main(int argc, char* argv[])
{
 std::string config_filename;

 if (!(argc == 1 || argc == 3)) {
  usage();
  return 1;
 }

 if (argc == 3) {
  if (argv[1] != "-c"s) {
   usage();
   return 1;
  }

  config_filename = argv[2];
 }

 try {
  Config config{config_filename};
  
  PluginLoader plugin_loader(config);
  plugin_loader.load_plugins();

  if (!plugin_loader.validate_config())
   throw std::runtime_error("Couldn't find all configured plugins.");

  return run_server(config, plugin_loader.get_plugins());
 } catch (const std::exception& ex) {
  std::cout << "Error: " << ex.what() << std::endl;
  return 1;
 }
}