Compare commits
5 Commits
888af6021b
...
bfd1e7c19a
| Author | SHA1 | Date | |
|---|---|---|---|
| bfd1e7c19a | |||
| d1a99d7d04 | |||
| eab4dcb37d | |||
| a9d1c99bd2 | |||
| 0f2549d96c |
@ -7,5 +7,6 @@ cp -r frontend/static/ dist/
|
|||||||
# Delete the old static files and copy the new ones to the dist folder
|
# Delete the old static files and copy the new ones to the dist folder
|
||||||
rm -rf frontend/static/
|
rm -rf frontend/static/
|
||||||
cp -r frontend/src/index.html dist/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/modules/font-awesome/ dist/static/modules/font-awesome/
|
||||||
cp -r frontend/src/css/ dist/static/
|
cp -r frontend/src/css/ dist/static/
|
||||||
BIN
frontend/src/favicon.png
Executable file
BIN
frontend/src/favicon.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 5.3 KiB |
@ -7,6 +7,7 @@
|
|||||||
<link rel="stylesheet" href="/css/main.css">
|
<link rel="stylesheet" href="/css/main.css">
|
||||||
<link rel="stylesheet" href="/modules/font-awesome/css/all.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 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>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"><p>JavaScript is disabled. Please, enable it to use this application.</p></div>
|
<div id="app"><p>JavaScript is disabled. Please, enable it to use this application.</p></div>
|
||||||
|
|||||||
@ -22,13 +22,14 @@ export class DarkStyle extends SkeletonStyle {
|
|||||||
|
|
||||||
export class LightStyle extends SkeletonStyle {
|
export class LightStyle extends SkeletonStyle {
|
||||||
navbar(element: GefestElement): void {
|
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 {
|
applyStyle(html: string, element?: GefestElement): string {
|
||||||
if (!element)
|
if (!element)
|
||||||
element = GefestElement.fromHTML(html);
|
element = GefestElement.fromHTML(html);
|
||||||
//element.addClass("light-mode");
|
//element.addClass("light-mode");
|
||||||
|
element.addClass("bg-light");
|
||||||
element.addClass("text-dark");
|
element.addClass("text-dark");
|
||||||
this.navbar(element);
|
this.navbar(element);
|
||||||
return element.build(true);
|
return element.build(true);
|
||||||
|
|||||||
@ -1,17 +1,18 @@
|
|||||||
import { Router } from "express";
|
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 { NewsItem, getTestNews } from "../utils/news";
|
||||||
|
import authRequired from "../utils/auth-required";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get('/isAuthenticated', (req, res) => {
|
router.get('/isAuthenticated', (req, res) => {
|
||||||
const response = new Response(req.isAuthenticated);
|
const response = new ApiResponse(req.isAuthenticated);
|
||||||
return res.json(response.getAnswer());
|
return res.json(response.getAnswer());
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/news', (req, res) => {
|
router.get('/news', authRequired, (req, res) => {
|
||||||
const newsList : NewsItem[] = getTestNews();
|
const newsList : NewsItem[] = getTestNews();
|
||||||
const response = new Response(newsList);
|
const response = new ApiResponse(newsList);
|
||||||
return res.json(response.getAnswer());
|
return res.json(response.getAnswer());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -11,8 +11,6 @@ declare module 'express-serve-static-core' {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
app.use(express.static(path.join(__dirname, 'static')));
|
|
||||||
|
|
||||||
// Checking auth
|
// Checking auth
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
req.isAuthenticated = true; // Mock authentication, replace with real logic
|
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') });
|
res.sendFile('index.html', { root: path.join(__dirname, 'static') });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.use(express.static(path.join(__dirname, 'static')));
|
||||||
|
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
console.log(`Server is running at http://localhost:${port}`);
|
console.log(`Server is running at http://localhost:${port}`);
|
||||||
});
|
});
|
||||||
13
src/utils/auth-required.ts
Normal file
13
src/utils/auth-required.ts
Normal 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();
|
||||||
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
export interface NewsItem {
|
export interface NewsItem {
|
||||||
title : string;
|
title : string;
|
||||||
content : string;
|
content : string;
|
||||||
|
//source: string;
|
||||||
publishedAt : Date;
|
publishedAt : Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -12,6 +13,66 @@ export function getTestNews (): NewsItem[] {
|
|||||||
title: "Lorem Ispum",
|
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,",
|
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()
|
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()
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -1,13 +1,32 @@
|
|||||||
import { response } from "express";
|
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;
|
data: T;
|
||||||
|
|
||||||
constructor(data: T) {
|
constructor(data: T) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAnswer(): { response: T } {
|
getAnswer(): { response: T } | { error: ApiError } {
|
||||||
|
if (isApiError(this.data)) {
|
||||||
|
return {
|
||||||
|
error: this.data
|
||||||
|
};
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
response: this.data
|
response: this.data
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user