Reorganising further
This commit is contained in:
@@ -8,5 +8,12 @@ set(CMAKE_BUILD_TYPE Debug)
|
||||
set(CMAKE_CXX_FLAGS "-Wall -g -fsanitize=address")
|
||||
|
||||
add_executable(Webserver "src/Entry.cpp" "src/Webserver.cpp" "src/HTTP.cpp"
|
||||
"libs/QuickDigest5/quickdigest5.cpp")
|
||||
"libs/QuickDigest5/quickdigest5.cpp" "src/Helpers.cpp")
|
||||
|
||||
add_custom_command(
|
||||
TARGET Webserver
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/www
|
||||
$<TARGET_FILE_DIR:Webserver>/www)
|
||||
|
||||
target_link_libraries(Webserver PRIVATE)
|
||||
|
@@ -1,4 +1,6 @@
|
||||
#include "main.hpp"
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
|
||||
// Entry point a.k.a "main.cpp"
|
||||
// You do not want to program here 99% of the time
|
||||
|
@@ -1,10 +1,5 @@
|
||||
#include "Helpers.hpp"
|
||||
#include "main.hpp"
|
||||
#include <asio/impl/write.hpp>
|
||||
#include <cstddef>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <system_error>
|
||||
|
||||
void HTTPrequest::start() {
|
||||
// Possible Logging here
|
||||
@@ -67,9 +62,7 @@ void HTTPrequest::processRequest(
|
||||
switch (Helpers::Pathhash(requestPath)) {
|
||||
case "/"_hash:
|
||||
responseStream << "200 OK" << responseMeta
|
||||
<< "<html><head><title>Hello "
|
||||
"you!</title></head><body><h1>Test</h1><p>pretty "
|
||||
"cool</p></body></html>";
|
||||
<< Helpers::ReadFile("www/index.html");
|
||||
break;
|
||||
}
|
||||
writeData(responseStream.str());
|
||||
|
11
src/Helpers.cpp
Normal file
11
src/Helpers.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "Helpers.hpp"
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
// Should add caching here
|
||||
std::string Helpers::ReadFile(std::string Path) {
|
||||
std::ifstream file(Path);
|
||||
std::stringstream contents;
|
||||
contents << file.rdbuf();
|
||||
return contents.str();
|
||||
}
|
@@ -2,10 +2,16 @@
|
||||
// https://medium.com/@ryan_forrester_/using-switch-statements-with-strings-in-c-a-complete-guide-efa12f64a59d
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
// This is called a polynomial rolling hash, prob going to collide
|
||||
namespace Helpers {
|
||||
std::string ReadFile(std::string Path);
|
||||
|
||||
// ===========
|
||||
// Hashing
|
||||
// ===========
|
||||
// This is called a polynomial rolling hash, prob going to collide
|
||||
constexpr uint64_t Pathhash(std::string_view s) {
|
||||
uint64_t res = 0;
|
||||
for (uint8_t c : s) {
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#include "main.hpp"
|
||||
#include <iostream>
|
||||
|
||||
// Webserver is defined at main.hpp, you probably do not want to code here
|
||||
Webserver::Webserver(asio::io_context &context)
|
||||
|
@@ -10,11 +10,7 @@
|
||||
#include <asio/placeholders.hpp>
|
||||
#include <asio/streambuf.hpp>
|
||||
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <istream>
|
||||
#include <string>
|
||||
#include <system_error>
|
||||
#include <unordered_map>
|
||||
|
||||
#define IP "127.0.0.1"
|
||||
|
@@ -8,7 +8,7 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<h1>Test</h1>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
Reference in New Issue
Block a user