- fixed routes

- added head and foot partials
- prepared bootstrap
This commit is contained in:
Sören Oesterwind 2023-05-01 18:31:10 +02:00
parent 6f35764a21
commit 5a21e56e80
13 changed files with 62 additions and 21 deletions

View File

@ -1,12 +1,13 @@
{ {
"allowedStaticFiles": [ "allowedStaticFiles": [
"bootstrap-icons/font/bootstrap-icons.css", "/bootstrap-icons/font/bootstrap-icons.css",
"bootstrap/dist/css/bootstrap.min.css", "/bootstrap/dist/css/bootstrap.min.css",
"bootstrap/dist/js/bootstrap.bundle.min.js", "/bootstrap/dist/js/bootstrap.bundle.min.js",
"jquery/dist/jquery.min.js", "/jquery/dist/jquery.min.js",
"darkreader/darkreader.js", "/darkreader/darkreader.js",
"bootstrap-icons/font/fonts/bootstrap-icons.woff2", "/bootstrap-icons/font/fonts/bootstrap-icons.woff2",
"bootstrap/dist/css/bootstrap.min.css.map" "/bootstrap/dist/css/bootstrap.min.css.map",
"/@popperjs/core/dist/cjs/popper.js"
], ],
"debugMode": false "debugMode": true
} }

2
package-lock.json generated
View File

@ -9,6 +9,7 @@
"version": "1.0.0", "version": "1.0.0",
"license": "GPL-3.0", "license": "GPL-3.0",
"dependencies": { "dependencies": {
"@popperjs/core": "^2.11.7",
"@prisma/client": "^4.13.0", "@prisma/client": "^4.13.0",
"bootstrap": "^5.3.0-alpha3", "bootstrap": "^5.3.0-alpha3",
"bootstrap-icons": "^1.10.5", "bootstrap-icons": "^1.10.5",
@ -202,7 +203,6 @@
"version": "2.11.7", "version": "2.11.7",
"resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.7.tgz", "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.7.tgz",
"integrity": "sha512-Cr4OjIkipTtcXKjAsm8agyleBuDHvxzeBoa1v543lbv1YaIwQjESsVcmjiWiPEbC1FIeHOG/Op9kdCmAmiS3Kw==", "integrity": "sha512-Cr4OjIkipTtcXKjAsm8agyleBuDHvxzeBoa1v543lbv1YaIwQjESsVcmjiWiPEbC1FIeHOG/Op9kdCmAmiS3Kw==",
"peer": true,
"funding": { "funding": {
"type": "opencollective", "type": "opencollective",
"url": "https://opencollective.com/popperjs" "url": "https://opencollective.com/popperjs"

View File

@ -17,6 +17,7 @@
"author": "[Project-Name-Here]", "author": "[Project-Name-Here]",
"license": "GPL-3.0", "license": "GPL-3.0",
"dependencies": { "dependencies": {
"@popperjs/core": "^2.11.7",
"@prisma/client": "^4.13.0", "@prisma/client": "^4.13.0",
"bootstrap": "^5.3.0-alpha3", "bootstrap": "^5.3.0-alpha3",
"bootstrap-icons": "^1.10.5", "bootstrap-icons": "^1.10.5",

View File

@ -0,0 +1,8 @@
<%~ E.includeFile("head.eta.html") %>
<div class="alert alert-primary" role="alert">
A simple primary alert—check it out!
</div>
<%~ E.includeFile("foot.eta.html") %>

View File

@ -0,0 +1,4 @@
<script src="/static/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="/static/@popperjs/core/dist/cjs/popper.js"></script>
</body>
</html>

View File

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>AssetFlow - Info about item</title>
<meta name="description" content="A simple HTML5 Template for new projects." />
<meta name="author" content="[Project-Name-Here]" />
<link rel="icon" href="/favicon.ico" />
<link rel="icon" href="/favicon.svg" type="image/svg+xml" />
<script src="/static/jquery/dist/jquery.min.js"></script>
<link href="/static/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="/static/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet">
</head>
<body>

View File

@ -41,7 +41,7 @@ export const prisma = new PrismaClient({
}); });
export const app = express(); export const app = express();
app.engine("html", require("eta").renderFile)
routes(app); routes(app);
app.listen(config.global.http_port, config.global.http_listen_address, () => { app.listen(config.global.http_port, config.global.http_listen_address, () => {

View File

@ -6,9 +6,6 @@ import setDemoData from './setDemoData.js';
// Router base is '/dev' // Router base is '/dev'
const Router = express.Router(); const Router = express.Router();
Router.use("/setDemoData", setDemoData) Router.use("/setDemoData", setDemoData)
export default Router; export default Router;

View File

@ -48,5 +48,5 @@ export default (req: Request, res: Response) => {
}); });
}); });
*/ */
res.send('Demo data added (not)'); res.status(200).send('Demo data added (not)');
}; };

View File

@ -0,0 +1,7 @@
import express, { Request, Response } from 'express';
import * as Eta from 'eta';
import { prisma, __path } from '../../index.js';
export default (req: Request, res: Response) => {
res.render(__path + '/src/frontend/demopage.eta.html');
};

View File

@ -3,11 +3,14 @@ import express from 'express';
// Route imports // Route imports
import skuRoute from './:id.js'; import skuRoute from './:id.js';
import testRoute from './test.js'; import testRoute from './test.js';
import etaTest from './etaTest.js';
// Router base is '/' // Router base is '/'
const Router = express.Router(); const Router = express.Router();
Router.use('/:id', skuRoute); Router.use('/etaTest', etaTest);
Router.use('/:id(\\w{8})', skuRoute);
Router.use('/test', testRoute); Router.use('/test', testRoute);
export default Router; export default Router;

View File

@ -2,9 +2,9 @@ import { Express } from 'express';
// Route imports // Route imports
import frontend_routes from './frontend/index.js'; import frontend_routes from './frontend/index.js';
import static_routes from './frontend/index.js'; import static_routes from './static/index.js';
import api_routes from './api/index.js'; import api_routes from './api/index.js';
import dev_routes from './frontend/index.js'; import dev_routes from './dev/index.js';
export default (app: Express) => { export default (app: Express) => {
app.use('/', frontend_routes); app.use('/', frontend_routes);

View File

@ -1,7 +1,7 @@
import express, { Request, Response } from 'express'; import express, { Request, Response } from 'express';
import * as fs from 'fs'; import * as fs from 'fs';
import * as Path from 'path'; import * as Path from 'path';
import { log } from '../../index.js'; import { log, __path } from '../../index.js';
// Router base is '/static' // Router base is '/static'
const Router = express.Router(); const Router = express.Router();
@ -11,14 +11,14 @@ const allowedURLs: Array<string> = JSON.parse(fs.readFileSync('allowedStaticPath
const recordedURLs: Array<string> = []; const recordedURLs: Array<string> = [];
const debugMode: boolean = JSON.parse(fs.readFileSync('allowedStaticPaths.json', 'utf8')).debugMode; const debugMode: boolean = JSON.parse(fs.readFileSync('allowedStaticPaths.json', 'utf8')).debugMode;
Router.use('/*', (req: Request, res: Response) => { Router.use('*', (req: Request, res: Response) => {
if (debugMode) { if (debugMode) {
res.sendFile(Path.join(__dirname, 'node_modules', req.params[0])); res.sendFile(Path.join(__path, 'node_modules', req.params[0]));
recordedURLs.push(req.params[0]); recordedURLs.push(req.params[0]);
log.web.debug(recordedURLs); log.web.debug(recordedURLs);
} else { } else {
if (allowedURLs.indexOf(req.params[0]) > -1) { if (allowedURLs.indexOf(req.params[0]) > -1) {
res.sendFile(Path.join(__dirname, 'node_modules', req.params[0])); res.sendFile(Path.join(__path, 'node_modules', req.params[0]));
} else { } else {
log.web.warn('Attempt to access restricted asset file ' + req.params[0]); log.web.warn('Attempt to access restricted asset file ' + req.params[0]);
res.status(403).json({ status: 'error', reason: 'Access to restricted asset file denied' }); res.status(403).json({ status: 'error', reason: 'Access to restricted asset file denied' });