Skip to content
This repository was archived by the owner on Mar 14, 2023. It is now read-only.

Commit 634c419

Browse files
author
clouless
committed
update dependencies and fix logging
1 parent d915743 commit 634c419

File tree

7 files changed

+218
-194
lines changed

7 files changed

+218
-194
lines changed

package.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "kartoffelstampf-server",
33
"description": "stampf it!",
4-
"version": "2.1.2",
4+
"version": "2.2.0",
55
"license": "MIT",
66
"repository": {
77
"type": "git",
@@ -21,15 +21,15 @@
2121
"cookie-parser": "~1.4.3",
2222
"cors": "^2.8.5",
2323
"debug": "~2.6.0",
24-
"express": "~4.14.1",
24+
"express": "~4.16.4",
2525
"file-type": "^4.1.0",
26-
"morgan": "~1.7.0",
27-
"multer": "^1.3.0",
26+
"morgan": "~1.9.1",
27+
"multer": "^1.4.1",
2828
"read-chunk": "^2.0.0",
2929
"serve-favicon": "~2.3.2",
3030
"ts-node": "^7.0.1",
31-
"winston": "^2.3.1",
32-
"ws": "^2.2.0"
31+
"winston": "^3.1.0",
32+
"ws": "^6.1.2"
3333
},
3434
"devDependencies": {
3535
"@types/chai": "^4.1.7",
@@ -41,7 +41,6 @@
4141
"@types/method-override": "0.0.29",
4242
"@types/morgan": "^1.7.32",
4343
"@types/serve-favicon": "^2.2.28",
44-
"@types/winston": "^2.2.0",
4544
"@types/ws": "0.0.39",
4645
"chai": "^4.2.0",
4746
"mocha": "^5.2.0",

src/express.app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as bodyParser from 'body-parser';
77
import * as cookieParser from 'cookie-parser';
88
import * as cors from 'cors';
99
import * as express from 'express';
10-
import * as logger from 'morgan';
10+
import * as morgan from 'morgan';
1111
import * as path from 'path';
1212
import * as favicon from 'serve-favicon';
1313

@@ -26,7 +26,7 @@ export class Server {
2626
// INIT
2727
this.app.use(cors());
2828
this.app.use(favicon(path.join(__dirname, '../public', 'favicon.ico')));
29-
this.app.use(logger('dev'));
29+
this.app.use(morgan('dev'));
3030
this.app.use(bodyParser.json({limit: '200mb'}));
3131
this.app.use(bodyParser.urlencoded({ extended: false}));
3232
this.app.use(cookieParser());

src/express.server.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import * as http from 'http';
99
import { IExpressError } from './error/IExpressError';
1010
import { Server } from './express.app';
11+
import { logger } from './services/LogService';
1112
import { WebSocketCommandService } from './services/WebSocketCommandService';
1213

1314
const onError = (error: IExpressError) => {
@@ -18,11 +19,11 @@ const onError = (error: IExpressError) => {
1819

1920
switch (error.code) {
2021
case 'EACCES':
21-
console.error(bind + ' requires elevated privileges');
22+
logger.log('error', bind + ' requires elevated privileges');
2223
process.exit(1);
2324
break;
2425
case 'EADDRINUSE':
25-
console.error(bind + ' is already in use');
26+
logger.log('error', ' is already in use');
2627
process.exit(1);
2728
break;
2829
default:

src/services/LogService.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as winston from 'winston';
2+
3+
export const logger = winston.createLogger({
4+
level: 'info',
5+
format: winston.format.json(),
6+
transports: [
7+
new winston.transports.Console({ format: winston.format.simple() }),
8+
],
9+
});

src/services/UploadFileHelper.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import * as crypto from 'crypto';
77
import * as fs from 'fs';
88
import { IntermediateImage } from '../data/IntermediateImage';
9+
import { logger } from './LogService';
910

1011
export class UploadFileHelper {
1112

@@ -58,9 +59,9 @@ export class UploadFileHelper {
5859
setTimeout(() => {
5960
try {
6061
fs.unlinkSync(this.TEMPORARY_FILE_PATH + fileName);
61-
console.log('deleted uploaded file: ', fileName);
62+
logger.log('info', 'deleted uploaded file: ', fileName);
6263
} catch (error) {
63-
console.log('failed to uploaded file: ', fileName);
64+
logger.log('info', 'failed to uploaded file: ', fileName);
6465
}
6566
}, 3600000); // 1h
6667
// -

src/services/WebSocketCommandService.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
import { spawn } from 'child_process';
77
import { Server } from 'http';
88
import * as url from 'url';
9-
import * as winston from 'winston';
109
import * as WebSocket from 'ws';
1110
import { IServerOptions, Server as WsServer } from 'ws';
1211
import { CommandInstruction } from '../data/CommandInstruction';
1312
import { CompressInstruction } from '../data/CompressInstruction';
1413
import { UploadFileHelper } from './UploadFileHelper';
14+
import { logger } from './LogService';
1515

1616
export class WebSocketCommandService {
1717

@@ -45,15 +45,15 @@ export class WebSocketCommandService {
4545
server: httpServer,
4646
};
4747
this.wss = new WsServer(options);
48+
logger.log('info', 'init logging');
4849
this.init();
4950
}
5051

5152
private init() {
5253
const self = this;
5354
self.wss.on('connection', (ws: WebSocket) => {
54-
const location = url.parse(ws.upgradeReq.url, true);
5555
ws.on('message', (message) => {
56-
winston.log('debug', 'received command instruction', message);
56+
logger.log('debug', 'received command instruction', message);
5757
// Interpret which command to execute => Prevent XSS Injects!
5858
const compressInstruction = JSON.parse(message) as CompressInstruction;
5959
const commandInstruction = this.compressCommandInstruction(compressInstruction);
@@ -82,7 +82,7 @@ export class WebSocketCommandService {
8282
type: 'stderr',
8383
}));
8484
} catch (error) {
85-
winston.log('debug', 'failed to send ws', error);
85+
logger.log('error', 'failed to send ws', error);
8686
}
8787
});
8888
cmd.stdout.on('data', (data: any) => {
@@ -94,7 +94,7 @@ export class WebSocketCommandService {
9494
type: 'stdout',
9595
}));
9696
} catch (error) {
97-
winston.log('debug', 'failed to send ws', error);
97+
logger.log('error', 'failed to send ws', error);
9898
}
9999
});
100100
cmd.stderr.on('data', (data: any) => {
@@ -106,7 +106,7 @@ export class WebSocketCommandService {
106106
type: 'stderr',
107107
}));
108108
} catch (error) {
109-
winston.log('debug', 'failed to send ws', error);
109+
logger.log('error', 'failed to send ws', error);
110110
}
111111
});
112112
cmd.on('exit', (code: Number) => {
@@ -122,7 +122,7 @@ export class WebSocketCommandService {
122122
// close after command is done
123123
ws.close();
124124
} catch (error) {
125-
winston.log('debug', 'failed to send ws', error);
125+
logger.log('error', 'failed to send ws', error);
126126
}
127127
});
128128
}

0 commit comments

Comments
 (0)