Move sku route to right place.

This commit is contained in:
Leon Meier 2023-05-01 00:14:16 +02:00
parent 30c2cd4732
commit 6f35764a21
3 changed files with 26 additions and 24 deletions

View File

@ -1,7 +1,6 @@
import { Signale } from 'signale'; import { Signale } from 'signale';
import ConfigHandler from './assets/configHandler'; import ConfigHandler from './assets/configHandler';
import express, { Request, Response } from 'express'; import express, { Request, Response } from 'express';
import * as Eta from 'eta';
import { PrismaClient } from '@prisma/client'; import { PrismaClient } from '@prisma/client';
import { Status, Category } from '@prisma/client'; import { Status, Category } from '@prisma/client';
import * as Path from 'path'; import * as Path from 'path';
@ -9,7 +8,7 @@ import * as fs from 'fs';
import routes from './routes/index.js'; import routes from './routes/index.js';
// Get app directory. // Get app directory.
const __path = process.argv[1]; export const __path = process.argv[1];
const logger_settings = { const logger_settings = {
disabled: false, disabled: false,
@ -43,27 +42,6 @@ export const prisma = new PrismaClient({
export const app = express(); 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); 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

@ -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');
}
});
};

View File

@ -1,11 +1,13 @@
import express from 'express'; import express from 'express';
// Route imports // Route imports
import skuRoute from './:id.js';
import testRoute from './test.js'; import testRoute from './test.js';
// Router base is '/' // Router base is '/'
const Router = express.Router(); const Router = express.Router();
Router.use("/test", testRoute) Router.use('/:id', skuRoute);
Router.use('/test', testRoute);
export default Router; export default Router;