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

Commit cf4d014

Browse files
prepare for release
1 parent baee1e0 commit cf4d014

File tree

4 files changed

+35
-12
lines changed

4 files changed

+35
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ node_modules/
2828
src/config/config.json
2929
src/key.pem
3030
src/cert.pem
31+
src/access.log

src/app.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const path = require('path');
1111
const minify = require('express-minify');
1212
const logger = require('morgan');
1313
const compression = require('compression');
14-
let debug = require('debug');
14+
const fs = require('fs');
1515
const index = require('./routes/index');
1616
const editor = require('./routes/editor');
1717
const legal = require('./routes/legal');
@@ -27,9 +27,12 @@ nunjucks.configure(path.join(__dirname, 'views'), {
2727
express: app
2828
});
2929

30+
// logger files
31+
var accessLogStream = fs.createWriteStream(path.join(__dirname, 'access.log'), { flags: 'a' })
32+
3033
// Adding middleware
3134
if (config.PRODUCTION) {
32-
app.use(logger('combined'));
35+
app.use(logger('combined', { stream: accessLogStream }));
3336
app.use(compression());
3437
}
3538
else {
@@ -38,12 +41,14 @@ else {
3841
app.use(minify({ jsMatch: false }));
3942

4043
// Prometheus middleware
44+
// TODO new middleware
4145
if(config.METRICS){
4246
app.use(promBundle({
4347
includeMethod: true,
4448
includePath: true,
4549
}));
4650
}
51+
4752
app.use(express.json());
4853
app.use(express.urlencoded({extended: false}));
4954
// Set static folder
@@ -62,7 +67,9 @@ app.all('*', (req, res) => {
6267

6368
// Handle errors
6469
app.use((error, req, res, next) => {
65-
debug(error);
70+
if (config.DEBUG) {
71+
console.error(error);
72+
}
6673
res.sendStatus(500);
6774
});
6875

src/db/MongoDB.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ const baseCode = [
1313

1414
class MongoDB {
1515
constructor (username, password, host, database, port) {
16-
const url = `mongodb://${username}:${password}@${host}:${port}/?retryWrites=true&w=majority`;
16+
let url = `mongodb://${username}:${password}@${host}:${port}/?retryWrites=true&w=majority`;
17+
url = 'mongodb://127.0.0.1:34919/7fd02636-cfe2-4691-980b-8fd1090347c3?';
1718
this.client = new MongoClient(url);
1819
}
1920

@@ -23,7 +24,9 @@ class MongoDB {
2324
this.codeWe = await this.db.db('codewe');
2425
this.documentsCollection = await this.codeWe.collection('codewe');
2526
} catch (err) {
26-
console.error('Error with db connection');
27+
if (configs.DEBUG) {
28+
console.error('Error with db connection');
29+
}
2730
throw new Error(err);
2831
}
2932
}
@@ -47,7 +50,9 @@ class MongoDB {
4750
this.documentsCollection.updateOne({_id: results.insertedId}, {$set: {documentLink: documentLink}})
4851
return documentLink;
4952
} catch (err) {
50-
console.error('Error when creating a new document');
53+
if (configs.DEBUG) {
54+
console.error('Error when creating a new document');
55+
}
5156
throw new Error(err);
5257
}
5358

@@ -57,7 +62,9 @@ class MongoDB {
5762
try {
5863
return await this.documentsCollection.findOne({documentLink: documentLink});
5964
} catch (err) {
60-
console.error('Error when fetching document');
65+
if (configs.DEBUG) {
66+
console.error('Error when fetching document');
67+
}
6168
throw new Error(err);
6269
}
6370
}
@@ -66,7 +73,9 @@ class MongoDB {
6673
try {
6774
await this.documentsCollection.updateOne({documentLink: documentLink, 'content.uuid': uuid}, {$set: {'content.$.content': content}});
6875
} catch (err) {
69-
console.error('Error when changing line content');
76+
if (configs.DEBUG) {
77+
console.error('Error when changing line content');
78+
}
7079
throw new Error(err);
7180
}
7281
}
@@ -89,7 +98,9 @@ class MongoDB {
8998
}
9099
});
91100
} catch (err) {
92-
console.error('Error when adding a new line to document');
101+
if (configs.DEBUG) {
102+
console.error('Error when adding a new line to document');
103+
}
93104
throw new Error(err);
94105
}
95106
}
@@ -99,7 +110,9 @@ class MongoDB {
99110
// Delete line at the right place
100111
await this.documentsCollection.updateOne({documentLink: documentLink}, {$pull: {content: {uuid: uuid}}});
101112
} catch (err) {
102-
console.error('Error when deleting a line in document');
113+
if (configs.DEBUG) {
114+
console.error('Error when deleting a line in document');
115+
}
103116
throw new Error(err);
104117
}
105118

@@ -124,7 +137,9 @@ class MongoDB {
124137
}
125138
}
126139
} catch (err) {
127-
console.error('Error when applying requests');
140+
if (configs.DEBUG) {
141+
console.error('Error when applying requests');
142+
}
128143
throw new Error(err);
129144
}
130145
}

src/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ require('./socket/socket')(wss);
3232

3333

3434
server.listen(port, host, () => {
35-
console.log('Server Started!')
35+
console.log('Server Started!');
3636
});

0 commit comments

Comments
 (0)