summaryrefslogtreecommitdiffhomepage
path: root/webserver.cpp
blob: 2574272f7b666d3e8b9e00b5ff651df63534dab5 (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
#include "config.h"
#include "http.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};
  load_plugins(config);
  return http_server(argc, argv);
 } catch (const std::exception& ex) {
  std::cout << "Error: " << ex.what() << std::endl;
  return 1;
 }
}