diff --git a/StreamingWebserver.pro b/StreamingWebserver.pro index ff6dcc9..2d6757b 100644 --- a/StreamingWebserver.pro +++ b/StreamingWebserver.pro @@ -10,6 +10,8 @@ HEADERS += streamingwebserver.h SOURCES += main.cpp \ streamingwebserver.cpp +RESOURCES += resources.qrc + OTHER_FILES += .dockerignore \ Dockerfile diff --git a/htdocs/css/style.css b/htdocs/css/style.css new file mode 100644 index 0000000..e5bbd2e --- /dev/null +++ b/htdocs/css/style.css @@ -0,0 +1,3 @@ +/** + * Stylesheet + */ diff --git a/htdocs/index.html b/htdocs/index.html new file mode 100644 index 0000000..efa05d8 --- /dev/null +++ b/htdocs/index.html @@ -0,0 +1,21 @@ + + + + + + + 1000serien.com + + + + + + + +

1000serien.com

+

This page is still under construction

+ + + + + diff --git a/htdocs/js/script.js b/htdocs/js/script.js new file mode 100644 index 0000000..98b5d5f --- /dev/null +++ b/htdocs/js/script.js @@ -0,0 +1,3 @@ +/** + * Script + */ diff --git a/resources.qrc b/resources.qrc new file mode 100644 index 0000000..8787507 --- /dev/null +++ b/resources.qrc @@ -0,0 +1,7 @@ + + + htdocs/index.html + htdocs/css/style.css + htdocs/js/script.js + + diff --git a/streamingwebserver.cpp b/streamingwebserver.cpp index e041c0d..1acc9b3 100644 --- a/streamingwebserver.cpp +++ b/streamingwebserver.cpp @@ -1,5 +1,9 @@ #include "streamingwebserver.h" +#include +#include +#include + #include "httpclientconnection.h" #include "httpcontainers.h" @@ -12,9 +16,24 @@ void StreamingWebserver::handleRequest(HttpClientConnection *connection, const H { HttpResponse response; response.protocol = request.protocol; - response.statusCode = HttpResponse::StatusCode::NotFound; response.headers.insert(QStringLiteral("Server"), QStringLiteral("Hatschi Server 1.0")); response.headers.insert(QStringLiteral("Content-Type"), QStringLiteral("text/html")); - connection->sendResponse(response, tr("Not Found")); + auto path = QStringLiteral(":/StreamingWebserver/htdocs") % + QDir::separator() % + (request.path == QStringLiteral("/") ? QStringLiteral("index.html") : request.path); + + qDebug() << request.path << path; + + std::unique_ptr device = std::make_unique(path); + if(device->open(QIODevice::ReadOnly)) + { + response.statusCode = HttpResponse::StatusCode::OK; + connection->sendResponse(response, std::move(device)); + } + else + { + response.statusCode = HttpResponse::StatusCode::NotFound; + connection->sendResponse(response, tr("Not Found")); + } }