1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- // import express from 'express';
- const express = require('express')
- import { Request, Response } from 'express';
- import { BaseMessage, LoggingService } from '../dependencies/logging/services/logging-service';
- import { LogSetting } from '../dependencies/logging/type/datatype';
- import { Subject } from 'rxjs';
- const app = express();
- const port = 9999;
- let count = 0
- let logSettings: LogSetting = {
- cacheMessageLimit: 0,
- storage: "MongoDB",
- setting: {
- appName: 'Retransmission',
- appLocName: 'Local Mongo Buffer',
- logLocName: 'Local Mongo BUffer',
- },
- customSetting: {
- server: "localhost:27017",
- database: 'client'
- }
- }
- let logginService = new LoggingService()
- let incomingMessage: Subject<BaseMessage> = new Subject()
- logginService.init(logSettings).then(() => {
- logginService.subscribe(incomingMessage)
- }).catch((err) => console.error(err))
- // Middleware to parse JSON bodies
- app.use(express.json());
- // Handling a GET request
- app.get('/', (req: Request, res: Response) => {
- res.send('Hello, I am alive!');
- });
- // Handling a POST request
- app.post('/data', (req: Request, res: Response) => {
- const data = req.body;
- count++
- console.log(`${count} : ${data?.header?.messageID ?? 'undefined Data'}`)
- incomingMessage.next(data)
- // Send a JSON response
- res.json({ message: `Received data`, data: data });
- // res.send(`Received data: ${data?.header?.messageID ?? 'undefined Data'}`);
- });
- app.listen(port, () => {
- console.log(`Server is running at http://localhost:${port}`);
- });
|