Skip to content
This repository was archived by the owner on Oct 5, 2024. It is now read-only.

Commit abef6b9

Browse files
authored
improved 404 page + minor bug fixes
1 parent e1f7eb0 commit abef6b9

File tree

9 files changed

+163
-54
lines changed

9 files changed

+163
-54
lines changed

frontend/WSLocal.c

+15-17
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@
77
#include <string.h>
88
#include <errno.h>
99

10-
#define SRV_PREFIX "[\e[36m\e[1mSERV-LOCAL\e[0m] "
11-
#define SRV_STATIC_DIR "./assets/"
12-
#define SRV_BUILD_DIR "./html"
13-
#define SRV_404_TEMPLATE "./assets/404.nosehad"
14-
#define SRV_DEF_TEMPLATE "./assets/cms.nosehad"
15-
16-
#define SRV_PAGE_CONFIG "./assets/json/pages-config.json"
17-
18-
#define SRV_USEDEBUGMODE 2024 /* enable outomatic recompile on file change */
1910

2011
#ifdef SRV_USEDEBUGMODE
2112

@@ -50,16 +41,21 @@ SQLTree *staticFiles;
5041
XString static404;
5142
XString staticCMS;
5243

53-
#include "PageData.h"
44+
#include "PageData.hpp"
5445

5546
static struct MHD_Response *srv_response404()
5647
{
5748
return MHD_create_response_from_buffer(static404._size, (void *)static404._str, MHD_RESPMEM_PERSISTENT);
5849
}
5950

60-
static struct MHD_Response *srv_responseDef()
51+
static struct MHD_Response *srv_responseDef(char *route)
6152
{
62-
return MHD_create_response_from_buffer(staticCMS._size, (void *)staticCMS._str, MHD_RESPMEM_PERSISTENT);
53+
PageData* data;
54+
if((data = srv_optainDataForRoute(route)) == null)
55+
data = srv_optainDataForRoute("/"); /* use default route */
56+
57+
XString response = data->page_data;
58+
return MHD_create_response_from_buffer(response._size, (void *)response._str, MHD_RESPMEM_PERSISTENT);
6359
}
6460

6561
/* simple switch statement to examine content type of static file */
@@ -112,7 +108,7 @@ static enum MHD_Result srv_handleonreq(void *cls,
112108
/* only static allowed currently */
113109
if ((file = strremoveAdStart(url, "/static/")) == null)
114110
{
115-
response = srv_responseDef();
111+
response = srv_responseDef(url);
116112

117113
int ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
118114
MHD_destroy_response(response);
@@ -216,6 +212,8 @@ static void srv_loadFiles()
216212
}
217213
staticCMS = xstrcreatefromfiledescriptor(fd);
218214
close(fd);
215+
216+
srv_optainPageData();
219217
}
220218

221219
static void _radix_srv_start()
@@ -244,7 +242,7 @@ static void srv_unloadFiles()
244242
// sqtr_free(staticFiles);
245243

246244
/* custom free paradigma for SQTree, since FileData also has to be freed */
247-
for (; !sqtr_local_empty(staticFiles); free(sqtr_local_popl(staticFiles)))
245+
for (; !sqtr_local_empty(staticFiles);)
248246
{
249247
SQLNode *freen = sqtr_local_popl(staticFiles);
250248

@@ -259,6 +257,9 @@ static void srv_unloadFiles()
259257
/* free entire node */
260258
free(freen);
261259
}
260+
261+
srv_destroyPageData();
262+
262263
free(staticFiles);
263264
free(static404._str);
264265
free(staticCMS._str);
@@ -287,7 +288,6 @@ void radix_srv_start()
287288
debga(SRV_PREFIX "%s\n", __func__);
288289

289290
_radix_srv_start();
290-
srv_optainPageData();
291291

292292
if (pthread_create(&file_check, NULL, (void *(*)(void *)) & srv_filelistener, null) != 0)
293293
{
@@ -301,8 +301,6 @@ void radix_srv_exit()
301301
{
302302
debga(SRV_PREFIX "%s\n", __func__);
303303

304-
srv_destroyPageData();
305-
306304
if (pthread_detach(file_check) != 0) /* detach pthread */
307305
{
308306
debg(SRV_PREFIX);

frontend/assets/404.nosehad

+54-10
Original file line numberDiff line numberDiff line change
@@ -374,21 +374,65 @@ input[type="file"] {
374374
.hidden {
375375
display: none;
376376
}
377+
.wrap-404 {
378+
display: grid;
379+
border-radius: 5px;
380+
padding: 90px;
381+
text-align: left;
382+
}
383+
@media only screen and (min-width: 500px) {
384+
.wrap-404 {
385+
border: 2px solid #fff;
386+
padding: 90px;
387+
}
388+
}
389+
@media only screen and (max-width: 499px) {
390+
.wrap-404 {
391+
border-bottom: 2px solid #fff;
392+
padding: 0px 31px 70px 31px;
393+
}
394+
}
395+
.cntent-wrap {
396+
text-align: center;
397+
}
398+
button {
399+
margin-left: 3px;
400+
}
401+
p {
402+
margin-bottom: 0px;
403+
margin-left: 3px;
404+
}
405+
h1 {
406+
margin-top: 0px;
407+
margin-bottom: 3px;
408+
}
409+
._404 {
410+
color: #E63946;
411+
}
377412
</style>
378413
<meta name="viewport" content="width=device-width, initial-scale=1">
379-
<link rel="preconnect" href="https://fonts.googleapis.com">
380-
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
381-
<link
382-
href="https://fonts.googleapis.com/css2?family=Changa:[email protected]&family=Major+Mono+Display&family=Playfair+Display&display=swap"
383-
rel="stylesheet">
384414
</head>
385415
<body>
386-
<h1>404</h1>
387-
<h5>How did you end up here idiot?</h5>
416+
<div class="cntent-wrap">
417+
<div class="wrap-404">
418+
<p>How did you end up here?</p>
419+
<h1>
420+
<logo>RAdiXcHAt <span class="_404">404</span></logo>
421+
</h1>
422+
<div class="input-wrap">
423+
<button onclick="redirect('/')"><strong id="signup-text">Go Home <svg xmlns="http://www.w3.org/2000/svg"
424+
width="16" height="16" fill="currentColor" class="bi bi-houses-fill" viewBox="0 0 16 16">
425+
<path
426+
d="M7.207 1a1 1 0 0 0-1.414 0L.146 6.646a.5.5 0 0 0 .708.708L1 7.207V12.5A1.5 1.5 0 0 0 2.5 14h.55a2.5 2.5 0 0 1-.05-.5V9.415a1.5 1.5 0 0 1-.56-2.475l5.353-5.354z" />
427+
<path
428+
d="M8.793 2a1 1 0 0 1 1.414 0L12 3.793V2.5a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v3.293l1.854 1.853a.5.5 0 0 1-.708.708L15 8.207V13.5a1.5 1.5 0 0 1-1.5 1.5h-8A1.5 1.5 0 0 1 4 13.5V8.207l-.146.147a.5.5 0 1 1-.708-.708z" />
429+
</svg></strong></button>
430+
</div>
431+
</div>
432+
<p>Please submit a <a onclick="redirect('/bug-report')">bug report</a> if this is not your target destination...
433+
</p>
434+
</div>
388435
</body>
389436
<script type="text/javascript">
390-
document.addEventListener('contextmenu', function (event) {
391-
event.preventDefault();
392-
});
393437
</script>
394438
</html>

frontend/assets/cms.nosehad

+7-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ let cms_current_location;
1212
let cms_document_cache = new Map();
1313
let cms_startup_cache = new Map();
1414
let cms_loaded_scripts = new Map();
15+
function cms_getPageFile(route) {
16+
const page = cms_pages.find((page) => page['route'] === route);
17+
if (page)
18+
return page['static'];
19+
return "/static/404.nosehad";
20+
}
1521
function cms_loadScript(uri) {
1622
if (cms_loaded_scripts.get(uri))
1723
return;
@@ -75,12 +81,7 @@ function redirect(rlocation, r = true, ps = true) {
7581
cms_ov_responseText = cms_document_cache.get(rlocation);
7682
if (cms_ov_responseText != undefined)
7783
return;
78-
else if (rlocation.endsWith('login')) {
79-
xhttp.open("GET", "/static/login.nosehad", true);
80-
}
81-
else {
82-
xhttp.open("GET", "/static/landing.nosehad", true);
83-
}
84+
xhttp.open("GET", cms_getPageFile(rlocation), true);
8485
xhttp.send();
8586
}
8687
redirect(window.location.pathname, false);

frontend/assets/json/pages-config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
{
1111
"route":"/",
12-
"static": "/static/login.nosehad",
12+
"static": "/static/landing.nosehad",
1313
"title": "Radix Chat",
1414
"description": "The social media chat app with a new innovative concept: Chat with EVERYONE",
1515
"keywords": ["Radix", "Chat", "App", "Innovative"],

frontend/html/404.html

+62-12
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,75 @@
55
<title>404 - Not Found</title>
66
<style>
77
#include "generic/wrapper.css"
8-
</style>
9-
<meta name="viewport" content="width=device-width, initial-scale=1">
10-
<link rel="preconnect" href="https://fonts.googleapis.com">
11-
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
12-
<link
13-
href="https://fonts.googleapis.com/css2?family=Changa:[email protected]&family=Major+Mono+Display&family=Playfair+Display&display=swap"
14-
rel="stylesheet">
158

9+
.wrap-404 {
10+
display: grid;
11+
border-radius: 5px;
12+
padding: 90px;
13+
text-align: left;
14+
}
15+
16+
@media only screen and (min-width: 500px) {
17+
.wrap-404 {
18+
border: 2px solid PRIMARY_BG_2;
19+
padding: 90px;
20+
}
21+
}
22+
23+
@media only screen and (max-width: 499px) {
24+
.wrap-404 {
25+
border-bottom: 2px solid #fff;
26+
padding: 0px 31px 70px 31px;
27+
}
28+
}
29+
30+
.cntent-wrap {
31+
text-align: center;
32+
}
1633

34+
button {
35+
margin-left: 3px;
36+
}
37+
38+
p {
39+
margin-bottom: 0px;
40+
margin-left: 3px;
41+
}
42+
43+
h1 {
44+
margin-top: 0px;
45+
margin-bottom: 3px;
46+
}
47+
48+
._404 {
49+
color: PRIMARY_BUTTON_BG;
50+
}
51+
</style>
52+
<meta name="viewport" content="width=device-width, initial-scale=1">
1753
</head>
1854

1955
<body>
20-
<h1>404</h1>
21-
<h5>How did you end up here idiot?</h5>
56+
<div class="cntent-wrap">
57+
<div class="wrap-404">
58+
<p>How did you end up here?</p>
59+
<h1>
60+
<logo>RAdiXcHAt <span class="_404">404</span></logo>
61+
</h1>
62+
<div class="input-wrap">
63+
<button onclick="redirect('/')"><strong id="signup-text">Go Home <svg xmlns="http://www.w3.org/2000/svg"
64+
width="16" height="16" fill="currentColor" class="bi bi-houses-fill" viewBox="0 0 16 16">
65+
<path
66+
d="M7.207 1a1 1 0 0 0-1.414 0L.146 6.646a.5.5 0 0 0 .708.708L1 7.207V12.5A1.5 1.5 0 0 0 2.5 14h.55a2.5 2.5 0 0 1-.05-.5V9.415a1.5 1.5 0 0 1-.56-2.475l5.353-5.354z" />
67+
<path
68+
d="M8.793 2a1 1 0 0 1 1.414 0L12 3.793V2.5a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5v3.293l1.854 1.853a.5.5 0 0 1-.708.708L15 8.207V13.5a1.5 1.5 0 0 1-1.5 1.5h-8A1.5 1.5 0 0 1 4 13.5V8.207l-.146.147a.5.5 0 1 1-.708-.708z" />
69+
</svg></strong></button>
70+
</div>
71+
</div>
72+
<p>Please submit a <a onclick="redirect('/bug-report')">bug report</a> if this is not your target destination...
73+
</p>
74+
</div>
2275
</body>
2376
<script type="text/javascript">
24-
document.addEventListener('contextmenu', function (event) {
25-
event.preventDefault();
26-
});
2777
</script>
2878

2979
</html>

frontend/html/generic/Content/cms.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "../../../properties.h"
2+
13
let cms_pages = C_PRELOAD_CONST_PAGES;
24

35
let cms_ov_responseText;
@@ -8,6 +10,14 @@ let cms_document_cache = new Map();
810
let cms_startup_cache = new Map();
911
let cms_loaded_scripts = new Map();
1012

13+
/* basically used to optaion the static path for a dynamic styled route */
14+
function cms_getPageFile(route) {
15+
const page = cms_pages.find((page) => page['route'] === route);
16+
if (page)
17+
return page['static'];
18+
return SRV_404_ROUTE;
19+
}
20+
1121
function cms_loadScript(uri) {
1222
if (cms_loaded_scripts.get(uri)) /* prevent script redeclaration */
1323
return;
@@ -92,13 +102,8 @@ function redirect(rlocation, r = true, ps = true) {
92102

93103
if (cms_ov_responseText != undefined)
94104
return;
95-
else if (rlocation.endsWith('login')) {
96-
xhttp.open("GET", "/static/login.nosehad", true);
97-
}
98-
else {
99-
xhttp.open("GET", "/static/landing.nosehad", true);
100-
}
101-
105+
106+
xhttp.open("GET", cms_getPageFile(rlocation), true);
102107
xhttp.send();
103108
}
104109

frontend/out/core

-24 Bytes
Binary file not shown.

frontend/properties.h

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
//#define RADIX_MAKE_APP
22
#define PORT 4564
3-
#define PORT_S "4564"
3+
#define PORT_S "4564"
4+
5+
#define SRV_PREFIX "[\e[36m\e[1mSERV-LOCAL\e[0m] "
6+
#define SRV_STATIC_DIR "./assets/"
7+
#define SRV_BUILD_DIR "./html"
8+
#define SRV_404_TEMPLATE "./assets/404.nosehad"
9+
#define SRV_404_ROUTE "/static/404.nosehad"
10+
#define SRV_DEF_TEMPLATE "./assets/cms.nosehad"
11+
12+
#define SRV_PAGE_CONFIG "./assets/json/pages-config.json"
13+
14+
#define SRV_USEDEBUGMODE 2024 /* enable outomatic recompile on file change */

frontend/utils/vgcore.108947

6.28 MB
Binary file not shown.

0 commit comments

Comments
 (0)