From 5a21e56e809b94240eb005393fa47a72696283a9 Mon Sep 17 00:00:00 2001 From: grey Date: Mon, 1 May 2023 18:31:10 +0200 Subject: [PATCH] - fixed routes - added head and foot partials - prepared bootstrap --- allowedStaticPaths.json | 17 +++++++++-------- package-lock.json | 2 +- package.json | 1 + src/frontend/demopage.eta.html | 8 ++++++++ src/frontend/foot.eta.html | 4 ++++ src/frontend/head.eta.html | 20 ++++++++++++++++++++ src/index.ts | 2 +- src/routes/dev/index.ts | 3 --- src/routes/dev/setDemoData.ts | 2 +- src/routes/frontend/etaTest.ts | 7 +++++++ src/routes/frontend/index.ts | 5 ++++- src/routes/index.ts | 4 ++-- src/routes/static/index.ts | 8 ++++---- 13 files changed, 62 insertions(+), 21 deletions(-) create mode 100644 src/frontend/demopage.eta.html create mode 100644 src/frontend/foot.eta.html create mode 100644 src/frontend/head.eta.html create mode 100644 src/routes/frontend/etaTest.ts diff --git a/allowedStaticPaths.json b/allowedStaticPaths.json index 825284e..ac33778 100644 --- a/allowedStaticPaths.json +++ b/allowedStaticPaths.json @@ -1,12 +1,13 @@ { "allowedStaticFiles": [ - "bootstrap-icons/font/bootstrap-icons.css", - "bootstrap/dist/css/bootstrap.min.css", - "bootstrap/dist/js/bootstrap.bundle.min.js", - "jquery/dist/jquery.min.js", - "darkreader/darkreader.js", - "bootstrap-icons/font/fonts/bootstrap-icons.woff2", - "bootstrap/dist/css/bootstrap.min.css.map" + "/bootstrap-icons/font/bootstrap-icons.css", + "/bootstrap/dist/css/bootstrap.min.css", + "/bootstrap/dist/js/bootstrap.bundle.min.js", + "/jquery/dist/jquery.min.js", + "/darkreader/darkreader.js", + "/bootstrap-icons/font/fonts/bootstrap-icons.woff2", + "/bootstrap/dist/css/bootstrap.min.css.map", + "/@popperjs/core/dist/cjs/popper.js" ], - "debugMode": false + "debugMode": true } diff --git a/package-lock.json b/package-lock.json index 169539e..830866d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "license": "GPL-3.0", "dependencies": { + "@popperjs/core": "^2.11.7", "@prisma/client": "^4.13.0", "bootstrap": "^5.3.0-alpha3", "bootstrap-icons": "^1.10.5", @@ -202,7 +203,6 @@ "version": "2.11.7", "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.7.tgz", "integrity": "sha512-Cr4OjIkipTtcXKjAsm8agyleBuDHvxzeBoa1v543lbv1YaIwQjESsVcmjiWiPEbC1FIeHOG/Op9kdCmAmiS3Kw==", - "peer": true, "funding": { "type": "opencollective", "url": "https://opencollective.com/popperjs" diff --git a/package.json b/package.json index 598a7ed..eca0116 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "author": "[Project-Name-Here]", "license": "GPL-3.0", "dependencies": { + "@popperjs/core": "^2.11.7", "@prisma/client": "^4.13.0", "bootstrap": "^5.3.0-alpha3", "bootstrap-icons": "^1.10.5", diff --git a/src/frontend/demopage.eta.html b/src/frontend/demopage.eta.html new file mode 100644 index 0000000..17e503a --- /dev/null +++ b/src/frontend/demopage.eta.html @@ -0,0 +1,8 @@ +<%~ E.includeFile("head.eta.html") %> + + + + +<%~ E.includeFile("foot.eta.html") %> \ No newline at end of file diff --git a/src/frontend/foot.eta.html b/src/frontend/foot.eta.html new file mode 100644 index 0000000..b0781b2 --- /dev/null +++ b/src/frontend/foot.eta.html @@ -0,0 +1,4 @@ + + + + diff --git a/src/frontend/head.eta.html b/src/frontend/head.eta.html new file mode 100644 index 0000000..5b386b8 --- /dev/null +++ b/src/frontend/head.eta.html @@ -0,0 +1,20 @@ + + + + + + + + AssetFlow - Info about item + + + + + + + + + + + + \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 573adf2..53fae9a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -41,7 +41,7 @@ export const prisma = new PrismaClient({ }); export const app = express(); - +app.engine("html", require("eta").renderFile) routes(app); app.listen(config.global.http_port, config.global.http_listen_address, () => { diff --git a/src/routes/dev/index.ts b/src/routes/dev/index.ts index e86d444..98fe883 100644 --- a/src/routes/dev/index.ts +++ b/src/routes/dev/index.ts @@ -6,9 +6,6 @@ import setDemoData from './setDemoData.js'; // Router base is '/dev' const Router = express.Router(); - - Router.use("/setDemoData", setDemoData) - export default Router; diff --git a/src/routes/dev/setDemoData.ts b/src/routes/dev/setDemoData.ts index a85a1d8..d527736 100644 --- a/src/routes/dev/setDemoData.ts +++ b/src/routes/dev/setDemoData.ts @@ -48,5 +48,5 @@ export default (req: Request, res: Response) => { }); }); */ - res.send('Demo data added (not)'); + res.status(200).send('Demo data added (not)'); }; diff --git a/src/routes/frontend/etaTest.ts b/src/routes/frontend/etaTest.ts new file mode 100644 index 0000000..b782bec --- /dev/null +++ b/src/routes/frontend/etaTest.ts @@ -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'); +}; \ No newline at end of file diff --git a/src/routes/frontend/index.ts b/src/routes/frontend/index.ts index 2ba1b9f..6f79d39 100644 --- a/src/routes/frontend/index.ts +++ b/src/routes/frontend/index.ts @@ -3,11 +3,14 @@ import express from 'express'; // Route imports import skuRoute from './:id.js'; import testRoute from './test.js'; +import etaTest from './etaTest.js'; // Router base is '/' const Router = express.Router(); -Router.use('/:id', skuRoute); +Router.use('/etaTest', etaTest); +Router.use('/:id(\\w{8})', skuRoute); Router.use('/test', testRoute); + export default Router; diff --git a/src/routes/index.ts b/src/routes/index.ts index bbca668..a7c0c97 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -2,9 +2,9 @@ import { Express } from 'express'; // Route imports 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 dev_routes from './frontend/index.js'; +import dev_routes from './dev/index.js'; export default (app: Express) => { app.use('/', frontend_routes); diff --git a/src/routes/static/index.ts b/src/routes/static/index.ts index ae8366a..772721b 100644 --- a/src/routes/static/index.ts +++ b/src/routes/static/index.ts @@ -1,7 +1,7 @@ import express, { Request, Response } from 'express'; import * as fs from 'fs'; import * as Path from 'path'; -import { log } from '../../index.js'; +import { log, __path } from '../../index.js'; // Router base is '/static' const Router = express.Router(); @@ -11,14 +11,14 @@ const allowedURLs: Array = JSON.parse(fs.readFileSync('allowedStaticPath const recordedURLs: Array = []; 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) { - 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]); log.web.debug(recordedURLs); } else { 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 { 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' });