summaryrefslogtreecommitdiffhomepage
path: root/webserver.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-04-03 13:54:08 +0200
committerRoland Reichwein <mail@reichwein.it>2020-04-03 13:54:08 +0200
commitd8c3333e7a7330c10bb96e426482e2b158011251 (patch)
tree761dbe37aa3da1900826ffc8db6d89ecdea96927 /webserver.cpp
parente60bb89a6d1392c0007a1fbc03faf007faf76167 (diff)
Added configuration file (WIP)
Diffstat (limited to 'webserver.cpp')
-rw-r--r--webserver.cpp36
1 files changed, 35 insertions, 1 deletions
diff --git a/webserver.cpp b/webserver.cpp
index 4b6a89c..b079707 100644
--- a/webserver.cpp
+++ b/webserver.cpp
@@ -1,6 +1,40 @@
+#include "config.h"
#include "http.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[])
{
- return http_server(argc, 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};
+ return http_server(argc, argv);
+ } catch (const std::exception& ex) {
+ std::cout << "Error: " << ex.what() << std::endl;
+ return 1;
+ }
}