Compare commits

...

5 Commits

Author SHA1 Message Date
bfd1e7c19a fix light theme 2026-04-26 22:26:41 +03:00
d1a99d7d04 fix static bug 2026-04-26 22:26:02 +03:00
eab4dcb37d Add ApiError and handling auth 2026-04-26 22:25:26 +03:00
a9d1c99bd2 connect the icon 2026-04-26 22:21:07 +03:00
0f2549d96c Add icon 2026-04-26 22:19:14 +03:00
9 changed files with 106 additions and 9 deletions

View File

@ -7,5 +7,6 @@ cp -r frontend/static/ dist/
# Delete the old static files and copy the new ones to the dist folder
rm -rf frontend/static/
cp -r frontend/src/index.html dist/static/
cp -r frontend/src/favicon.png dist/static/
cp -r frontend/src/modules/font-awesome/ dist/static/modules/font-awesome/
cp -r frontend/src/css/ dist/static/

BIN
frontend/src/favicon.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

@ -7,6 +7,7 @@
<link rel="stylesheet" href="/css/main.css">
<link rel="stylesheet" href="/modules/font-awesome/css/all.css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel="icon" type="image/png" href="/favicon.png"/>
</head>
<body>
<div id="app"><p>JavaScript is disabled. Please, enable it to use this application.</p></div>

View File

@ -22,13 +22,14 @@ export class DarkStyle extends SkeletonStyle {
export class LightStyle extends SkeletonStyle {
navbar(element: GefestElement): void {
// Nothing add. Bg is light by default, and text is dark by default, so we don't need to add any classes for the navbar in the light style.
//element.addClass("light-navbar");
}
applyStyle(html: string, element?: GefestElement): string {
if (!element)
element = GefestElement.fromHTML(html);
//element.addClass("light-mode");
element.addClass("bg-light");
element.addClass("text-dark");
this.navbar(element);
return element.build(true);

View File

@ -1,17 +1,18 @@
import { Router } from "express";
import { Response } from '../utils/rest-api-answer';
import { ApiResponse } from '../utils/rest-api-answer';
import { NewsItem, getTestNews } from "../utils/news";
import authRequired from "../utils/auth-required";
const router = Router();
router.get('/isAuthenticated', (req, res) => {
const response = new Response(req.isAuthenticated);
const response = new ApiResponse(req.isAuthenticated);
return res.json(response.getAnswer());
});
router.get('/news', (req, res) => {
router.get('/news', authRequired, (req, res) => {
const newsList : NewsItem[] = getTestNews();
const response = new Response(newsList);
const response = new ApiResponse(newsList);
return res.json(response.getAnswer());
});

View File

@ -11,8 +11,6 @@ declare module 'express-serve-static-core' {
}
}
app.use(express.static(path.join(__dirname, 'static')));
// Checking auth
app.use((req, res, next) => {
req.isAuthenticated = true; // Mock authentication, replace with real logic
@ -36,6 +34,8 @@ app.get('/home', (req, res) => {
res.sendFile('index.html', { root: path.join(__dirname, 'static') });
});
app.use(express.static(path.join(__dirname, 'static')));
app.listen(port, () => {
console.log(`Server is running at http://localhost:${port}`);
});

View File

@ -0,0 +1,13 @@
import { NextFunction, Response, Request } from "express";
import { ApiResponse, ApiError } from "./rest-api-answer";
export default function (req : Request, res: Response, next: NextFunction) {
if (!req.isAuthenticated) {
const error : ApiResponse<ApiError> = new ApiResponse({
code: "AUTH_REQUIRES",
message: "Authentication is required"
});
return res.status(401).json(error);
}
next();
}

View File

@ -1,6 +1,7 @@
export interface NewsItem {
title : string;
content : string;
//source: string;
publishedAt : Date;
}
@ -12,6 +13,66 @@ export function getTestNews (): NewsItem[] {
title: "Lorem Ispum",
content: "Lorem Ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet,",
publishedAt: new Date()
},
{
title: "News Item 1",
content: "This is the content for news item 1. It contains some sample text to demonstrate the news functionality.",
publishedAt: new Date()
},
{
title: "News Item 2",
content: "This is the content for news item 2. Another piece of sample news content for testing purposes.",
publishedAt: new Date()
},
{
title: "News Item 3",
content: "News item 3 brings you the latest updates. Stay informed with our regular news feed.",
publishedAt: new Date()
},
{
title: "News Item 4",
content: "Content for the fourth news item. This is part of the test data for the application.",
publishedAt: new Date()
},
{
title: "News Item 5",
content: "Fifth news item in the list. More sample content to populate the news array.",
publishedAt: new Date()
},
{
title: "News Item 6",
content: "This is news item number six. Continuing to add test data for the news feature.",
publishedAt: new Date()
},
{
title: "News Item 7",
content: "Seventh item in the news feed. Sample text to ensure the array has sufficient data.",
publishedAt: new Date()
},
{
title: "News Item 8",
content: "News item eight provides more content. This helps in testing the display of multiple items.",
publishedAt: new Date()
},
{
title: "News Item 9",
content: "The ninth news item. Almost reaching the total of 13 items including the original.",
publishedAt: new Date()
},
{
title: "News Item 10",
content: "Tenth item in the array. This completes the set of additional news items requested.",
publishedAt: new Date()
},
{
title: "News Item 11",
content: "Eleventh news item. Continuing to add variety to the test data.",
publishedAt: new Date()
},
{
title: "News Item 12",
content: "The twelfth and final news item. This brings the total to 13 items in the array.",
publishedAt: new Date()
}
];
}

View File

@ -1,13 +1,32 @@
import { response } from "express";
export class Response<T> {
export interface ApiError {
code: string;
message: string;
}
function isApiError(value: unknown): value is ApiError {
return (
value !== null &&
typeof value === "object" &&
"code" in value &&
"message" in value
);
}
export class ApiResponse<T> {
data: T;
constructor(data: T) {
this.data = data;
}
getAnswer(): { response: T } {
getAnswer(): { response: T } | { error: ApiError } {
if (isApiError(this.data)) {
return {
error: this.data
};
}
return {
response: this.data
};