Connected fron t to back

This commit is contained in:
Андреев Григорий 2024-08-06 12:33:20 +03:00
parent 49a4414bc8
commit b9445e6796
6 changed files with 29 additions and 15 deletions

View File

@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Веб-Чат</title>
<link rel="stylesheet" href="assets/css/chat.css">
<link rel="stylesheet" href="/assets/css/chat.css">
</head>
<body>
<div class="chat-container">
@ -20,6 +20,6 @@
</div>
</div>
<script src="assets/js/chat.js"></script>
<script src="/assets/js/chat.js"></script>
</body>
</html>

View File

@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Список Чат-Комнат</title>
<link rel="stylesheet" href="assets/css/list-rooms.css">
<link rel="stylesheet" href="/assets/css/list-rooms.css">
</head>
<body>
<div class="container">
@ -47,6 +47,6 @@
</div>
</div>
<script src="assets/js/list-rooms.js"></script>
<script src="/assets/js/list-rooms.js"></script>
</body>
</html>

View File

@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="assets/css/profile.css">
<link rel="stylesheet" href="/assets/css/profile.css">
<title>Профиль</title>
</head>
<body>
@ -13,7 +13,7 @@
<form>
<div class="columns">
<div class="column">
<img class="avatar" src="../img/empty_avatar.png" id="avatar" height="200" width="200"><br>
<img class="avatar" src="/assets/img/empty_avatar.png" id="avatar" height="200" width="200"><br>
<input type="file" id="fileInput" style="display:none">
<button class="add" type="button" onclick="document.getElementById('fileInput').click();"></button><br>
</div>
@ -30,7 +30,7 @@
</form>
</div>
<script src="assets/js/list-rooms.js"> </script>
<script src="/assets/js/list-rooms.js"> </script>
</body>
</html>

View File

@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Страница Регистрации</title>
<link rel="stylesheet" href="assets/css/registration.css">
<link rel="stylesheet" href="/assets/css/registration.css">
</head>
<body>
@ -17,7 +17,7 @@
<button type="submit">Зарегистрироваться</button>
</form>
</div>
<script src="assets/js/registration.js"></script>
<script src="/assets/js/registration.js"></script>
</body>
</html>

View File

@ -99,6 +99,8 @@ namespace een9 {
if (p.first == "Content-Length") {
collecting_body = res.has_body = true;
body_size = std::stoull(p.second);
if (body_size > 100000000)
THROW("Message content is too big");
res.body.reserve(body_size);
}
}

View File

@ -57,6 +57,9 @@ int main(int argc, char** argv){
een9::StaticAssetManagerRule{assets_dir + "/html", "/assets/html", {{".html", "text/html"}} },
een9::StaticAssetManagerRule{assets_dir + "/css", "/assets/css", {{".css", "text/css"}} },
een9::StaticAssetManagerRule{assets_dir + "/js", "/assets/js", {{".js", "text/js"}} },
een9::StaticAssetManagerRule{assets_dir + "/img", "/assets/img", {
{".jpg", "image/jpg"}, {".png", "image/png"}, {".svg", "image/svg+xml"}
} },
});
een9::MainloopParameters params;
@ -68,15 +71,24 @@ int main(int argc, char** argv){
std::string text = unsafe_client_request_stringification(req);
return een9::form_http_server_response_200("text/plain", text);
}
if (req.uri_path == "/" || req.uri_path == "/index.html") {
for (auto& p: een9::split_html_query(req.uri_query)) {
printf("Query: %s = %s\n", p.first.c_str(), p.second.c_str());
}
printf("");
ret = samI.get_asset("/assets/html/test.html", sa);
auto rteee = [&](const std::string& asset_path) -> std::string {
ret = samI.get_asset(asset_path, sa);
een9_ASSERT_pl(ret == 0);
return een9::form_http_server_response_200(sa.type, sa.content);
};
if (req.uri_path == "/" || req.uri_path == "/list-rooms") {
return rteee("/assets/html/list-rooms.html");
}
if (req.uri_path == "/chat") {
return rteee("/assets/html/chat.html");
}
if (req.uri_path == "/profile") {
return rteee("/assets/html/profile.html");
}
if (req.uri_path == "/registration") {
return rteee("/assets/html/registration.html");
}
/* Trying to interpret request as asset lookup */
ret = samI.get_asset(req.uri_path, sa);
if (ret >= 0) {
return een9::form_http_server_response_200(sa.type, sa.content);