2023-04-30 22:04:13 +02:00
|
|
|
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';
|
|
|
|
import * as fs from 'fs';
|
2023-05-01 00:07:13 +02:00
|
|
|
import routes from './routes/index.js';
|
2023-04-30 22:04:13 +02:00
|
|
|
|
|
|
|
// Get app directory.
|
|
|
|
const __path = process.argv[1];
|
|
|
|
|
|
|
|
const logger_settings = {
|
|
|
|
disabled: false,
|
|
|
|
logLevel: 'info',
|
|
|
|
scope: 'Core',
|
|
|
|
stream: process.stdout,
|
|
|
|
displayFilename: true
|
|
|
|
};
|
|
|
|
|
|
|
|
const coreLogger = new Signale(logger_settings);
|
2023-05-01 00:07:13 +02:00
|
|
|
export const log = {
|
2023-04-30 22:04:13 +02:00
|
|
|
core: coreLogger,
|
|
|
|
db: coreLogger.scope('DB'),
|
|
|
|
web: coreLogger.scope('WEB')
|
|
|
|
};
|
|
|
|
|
|
|
|
// Create a new config instance.
|
|
|
|
const config = new ConfigHandler(__path + '/config.json', {
|
|
|
|
db_connection_string: 'mysql://USER:PASSWORD@HOST:3306/DATABASE',
|
|
|
|
http_listen_address: '127.0.0.1',
|
|
|
|
http_port: 3000
|
|
|
|
});
|
|
|
|
|
2023-05-01 00:07:13 +02:00
|
|
|
export const prisma = new PrismaClient({
|
2023-04-30 22:04:13 +02:00
|
|
|
datasources: {
|
|
|
|
db: {
|
|
|
|
url: config.global.db_connection_string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-05-01 00:07:13 +02:00
|
|
|
export const app = express();
|
2023-04-30 22:04:13 +02:00
|
|
|
|
2023-05-01 00:07:13 +02:00
|
|
|
/*
|
2023-04-30 22:04:13 +02:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2023-05-01 00:07:13 +02:00
|
|
|
*/
|
2023-04-30 22:04:13 +02:00
|
|
|
|
|
|
|
routes(app);
|
|
|
|
|
|
|
|
app.listen(config.global.http_port, config.global.http_listen_address, () => {
|
|
|
|
log.web.info(`Listening at http://${config.global.http_listen_address}:${config.global.http_port}`);
|
|
|
|
});
|