assetflow/src/index.ts

66 lines
1.7 KiB
TypeScript
Raw Normal View History

import { Signale } from 'signale';
import ConfigHandler from './assets/configHandler';
import express, { Request, Response } from 'express';
import fileUpload from 'express-fileupload';
import { PrismaClient } from '@prisma/client';
import * as eta from 'eta';
import bodyParser from 'body-parser';
2023-05-01 00:07:13 +02:00
import routes from './routes/index.js';
// Get app directory.
2023-05-01 00:14:16 +02:00
export 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 = {
core: coreLogger,
db: coreLogger.scope('DB'),
web: coreLogger.scope('WEB')
};
// Create a new config instance.
export 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,
debug: false
});
2023-05-01 00:07:13 +02:00
export const prisma = new PrismaClient({
datasources: {
db: {
url: config.global.db_connection_string
}
}
});
2023-05-01 00:07:13 +02:00
export const app = express();
2023-05-04 20:21:10 +02:00
app.set('x-powered-by', false);
2023-05-15 01:37:51 +02:00
//app.set('strict routing', true);
2023-05-04 20:21:10 +02:00
app.engine('html', eta.renderFile);
// app.use(cors());
app.use(bodyParser.urlencoded({ extended: false }));
// Using bodyParser to parse JSON bodies into JS objects
app.use(bodyParser.json());
app.use(fileUpload());
// Configure static https://expressjs.com/de/starter/static-files.html
// app.use('/static', express.static('public'));
2023-05-04 20:21:10 +02:00
app.use(express.static(__path + '/static'));
app.use(routes);
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}`);
});