Initial commit

This commit is contained in:
2022-12-24 14:32:13 +01:00
commit 3996e37682
17 changed files with 10283 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
import express from 'express';
export abstract class CommonRoutesConfig {
app: express.Application;
name: string;
constructor(app: express.Application, name: string) {
this.app = app;
this.name = name;
this.configureRoutes();
}
getName() {
return this.name;
}
abstract configureRoutes(): express.Application;
}
+52
View File
@@ -0,0 +1,52 @@
import * as appRoot from 'app-root-path';
import * as winston from 'winston';
const options = {
file_info: {
level: 'info',
filename: `${appRoot}/logs/app.log`,
handleExceptions: true,
json: true,
maxsize: 5242880, // 5MB
maxFiles: 5,
colorize: false
},
file_error: {
level: 'error',
filename: `${appRoot}/logs/error.log`,
handleExceptions: true,
json: true,
maxsize: 5242880, // 5MB
maxFiles: 5,
colorize: false
},
file_debug: {
level: 'debug',
filename: `${appRoot}/logs/debug.log`,
handleExceptions: true,
json: true,
maxsize: 5242880, // 5MB
maxFiles: 5,
colorize: false
},
console: {
level: 'debug',
handleExceptions: true,
json: false,
colorize: true
}
};
const logger: winston.Logger = winston.createLogger({
format: winston.format.combine(
winston.format.timestamp(),
winston.format.json()
),
transports: [
new winston.transports.File(options.file_info),
new winston.transports.File(options.file_error),
new winston.transports.File(options.file_debug),
new winston.transports.Console(options.console)
],
exitOnError: false // do not exit on handled exceptions
});
export default logger;
+19
View File
@@ -0,0 +1,19 @@
import * as dotenv from 'dotenv';
const mariadb = require('mariadb');
dotenv.config();
export namespace NachklangCalendarDB {
const pool = mariadb.createPool({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.CALENDAR_DB,
connectionLimit: 5
});
export const getConnection = async () => {
return pool.getConnection();
};
}
+26
View File
@@ -0,0 +1,26 @@
/**
* Required External Modules and Interfaces
*/
import express, {Request, Response} from 'express';
import {Guid} from 'guid-typescript';
import logger from '../../middleware/logger';
/**
* Router Definition
*/
export const calendarRouter = express.Router();
calendarRouter.get('/', async (req: Request, res: Response) => {
try {
res.status(200).send('Nachklang e.V. Calendar API Endpoint');
} catch (e: any) {
let errorGuid = Guid.create().toString();
logger.error('Error handling a request: ' + e.message, {reference: errorGuid});
res.status(500).send({
'status': 'PROCESSING_ERROR',
'message': 'Internal Server Error. Try again later.',
'reference': errorGuid
});
}
});