From 6f35764a215182f18915e8816eb3a9b8de75e045 Mon Sep 17 00:00:00 2001 From: Spacelord Date: Mon, 1 May 2023 00:14:16 +0200 Subject: [PATCH] Move sku route to right place. --- src/index.ts | 24 +----------------------- src/routes/frontend/:id.ts | 22 ++++++++++++++++++++++ src/routes/frontend/index.ts | 4 +++- 3 files changed, 26 insertions(+), 24 deletions(-) create mode 100644 src/routes/frontend/:id.ts diff --git a/src/index.ts b/src/index.ts index 42d912c..573adf2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,6 @@ import { Signale } from 'signale'; import ConfigHandler from './assets/configHandler'; import express, { Request, Response } from 'express'; -import * as Eta from 'eta'; import { PrismaClient } from '@prisma/client'; import { Status, Category } from '@prisma/client'; import * as Path from 'path'; @@ -9,7 +8,7 @@ import * as fs from 'fs'; import routes from './routes/index.js'; // Get app directory. -const __path = process.argv[1]; +export const __path = process.argv[1]; const logger_settings = { disabled: false, @@ -43,27 +42,6 @@ export const prisma = new PrismaClient({ export const app = express(); -/* -app.get('/:id', (req, res) => { - // retrieve data from database using id from url - prisma.item - .findFirst({ - where: { - SKU: req.params.id - } - }) - .then((item) => { - if (item) { - Eta.renderFile(__path + '/src/frontend/publicInfoPage.eta.html', item).then((html) => { - res.send(html); - }); - } else { - res.send('Item not found'); - } - }); -}); - */ - routes(app); app.listen(config.global.http_port, config.global.http_listen_address, () => { diff --git a/src/routes/frontend/:id.ts b/src/routes/frontend/:id.ts new file mode 100644 index 0000000..b676b51 --- /dev/null +++ b/src/routes/frontend/:id.ts @@ -0,0 +1,22 @@ +import { Request, Response } from 'express'; +import { prisma, __path } from '../../index.js'; +import * as Eta from 'eta'; + +export default (req: Request, res: Response) => { + // retrieve data from database using id from url + prisma.item + .findFirst({ + where: { + SKU: req.params.id + } + }) + .then((item) => { + if (item) { + Eta.renderFile(__path + '/src/frontend/publicInfoPage.eta.html', item).then((html) => { + res.send(html); + }); + } else { + res.send('Item not found'); + } + }); +}; diff --git a/src/routes/frontend/index.ts b/src/routes/frontend/index.ts index 0ae37c9..2ba1b9f 100644 --- a/src/routes/frontend/index.ts +++ b/src/routes/frontend/index.ts @@ -1,11 +1,13 @@ import express from 'express'; // Route imports +import skuRoute from './:id.js'; import testRoute from './test.js'; // Router base is '/' const Router = express.Router(); -Router.use("/test", testRoute) +Router.use('/:id', skuRoute); +Router.use('/test', testRoute); export default Router;