Adds webserver for serving UI elements
This commit is contained in:
1 parent
c3ababbf12
commit
f1da4e06f5
9 files changed
+7641
-4
No files matched your search
@@ -6,6 +6,9 @@ add_library(Asio INTERFACE IMPORTED GLOBAL)
|
||||
target_compile_options(Asio INTERFACE -D ASIO_STANDALONE)
|
||||
target_include_directories(Asio INTERFACE lib/asio/include)
|
||||
|
||||
add_library(HTTPLib INTERFACE IMPORTED GLOBAL)
|
||||
target_include_directories(HTTPLib INTERFACE lib/cpp-httplib/include)
|
||||
|
||||
find_package (Threads REQUIRED)
|
||||
target_link_libraries(Asio INTERFACE Threads::Threads)
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ The distributed approach to DNS
|
||||
|
||||
## Useful Commands
|
||||
```
|
||||
inotifywait -m -q -r -e close_write --format %f ../src/ | grep --line-buffered "\.[h,c]pp$" | while IFS= read -r file; do make && src/core/Plains; done
|
||||
inotifywait -m -q -r -e close_write --format %f ../src/ | grep --line-buffered "\.[h,c]pp$" | while IFS= read -r file; do make && cp -R ../static ./ && src/core/Plains; done
|
||||
```
|
||||
|
||||
## Coding Style
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2017 yhirose
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
+3
-1
@@ -26,7 +26,7 @@ int main(int args, char **argv) {
|
||||
{
|
||||
ConfigManager cfg(logger, arguments);
|
||||
EventBus eventBus(logger);
|
||||
UI::Server uiServer(logger, eventBus);
|
||||
UI::Server uiServer(logger, eventBus);
|
||||
Resolver::Server resolver(logger, eventBus);
|
||||
|
||||
/*
|
||||
@@ -57,6 +57,8 @@ int main(int args, char **argv) {
|
||||
//resolver.run();
|
||||
logger.info.ln ("PLAINS successfully started.");
|
||||
// Run something on main thread...
|
||||
std::this_thread::sleep_for(std::chrono::seconds(15));
|
||||
//std::cin.get();
|
||||
logger.info.ln ("Shutting down PLAINS. Good Bye!");
|
||||
}
|
||||
catch (Exception& e) {
|
||||
|
||||
@@ -3,4 +3,4 @@ add_library(UI OBJECT Server.cpp)
|
||||
|
||||
target_include_directories(UI PUBLIC include)
|
||||
|
||||
target_link_libraries(UI PRIVATE Core DNS PUBLIC Asio)
|
||||
target_link_libraries(UI PRIVATE Core DNS PUBLIC Asio HTTPLib)
|
||||
@@ -10,14 +10,40 @@ Server::Server(Logger& logger, EventBus& eventBus)
|
||||
_eventBus(eventBus)
|
||||
{
|
||||
_logger.debug.ln ("Starting UI Webserver...");
|
||||
_server = new httplib::Server;
|
||||
|
||||
//Set static file directory
|
||||
auto ret = _server->set_mount_point("/", "./static/ui");
|
||||
if (!ret) {
|
||||
_logger.fatal.ln ("UI static file directory static/ui not found!");
|
||||
}
|
||||
//Redirecto / to index.htm
|
||||
_server->Get("/", [this](const auto& req, auto& res) {
|
||||
res.set_redirect("/index.htm");
|
||||
});
|
||||
|
||||
_server->set_logger([this](const auto& req, const auto& res) {
|
||||
//your_logger(req, res);
|
||||
_logger.debug.ln ("UI Log message from Webserver. Implement passthrough!");
|
||||
});
|
||||
|
||||
_thread = thread(&Server::run, this);
|
||||
_logger.debug.ln ("UI Webserver started");
|
||||
}
|
||||
|
||||
Server::~Server() {
|
||||
_logger.debug.ln ("Stopping UI Webserver...");
|
||||
_server->stop();
|
||||
_thread.join();
|
||||
delete _server;
|
||||
_logger.debug.ln ("UI Webserver stopped");
|
||||
}
|
||||
|
||||
void Server::run() {
|
||||
_logger.info.ln ("UI Running Webserver on Port 8080");
|
||||
_server->listen("0.0.0.0", 8080);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#ifndef UI_SERVER_HPP
|
||||
#define UI_SERVER_HPP
|
||||
#include <thread>
|
||||
#include "asio.hpp"
|
||||
#include "Core.hpp"
|
||||
#include "httplib.h"
|
||||
|
||||
namespace Plains {
|
||||
namespace UI {
|
||||
@@ -9,6 +11,7 @@ namespace UI {
|
||||
using Core::EventBus;
|
||||
using Core::Logger;
|
||||
using Core::Exception;
|
||||
using std::thread;
|
||||
|
||||
|
||||
class Server
|
||||
@@ -18,6 +21,9 @@ class Server
|
||||
Logger& _logger;
|
||||
asio::io_context _ioContext;
|
||||
asio::ip::tcp::endpoint _sender_endpoint;
|
||||
httplib::Server* _server;
|
||||
thread _thread;
|
||||
void run();
|
||||
|
||||
public:
|
||||
Server(Logger& logger, EventBus& eventBus);
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Plains Control Panel</title>
|
||||
<title>PLAINS Control Panel</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" type="text/css" href="style.css" media="all" />
|
||||
</head>
|
||||
|
||||
Reference in new issue
Block a user