Skip to content

Commit b49996d

Browse files
committed
Adds config file
1 parent c0af13d commit b49996d

File tree

7 files changed

+34
-11
lines changed

7 files changed

+34
-11
lines changed

.prettierrc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all",
4+
"overrides": [
5+
{
6+
"files": ["**/.*rc", "**/*.json"],
7+
"options": { "parser": "json" }
8+
}
9+
]
10+
}

JavaScript/9-logger/config.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
transport: "http", // ws | http
3+
apiPort: 8001,
4+
staticPort: 8000,
5+
staticPath: "./static",
6+
logPath: "./log",
7+
db: {
8+
host: "127.0.0.1",
9+
port: 5432,
10+
database: "example",
11+
user: "marcus",
12+
password: "marcus",
13+
},
14+
};

JavaScript/9-logger/db.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
'use strict';
22

33
const pg = require('pg');
4+
const config = require('./config.js');
45

5-
const pool = new pg.Pool({
6-
host: '127.0.0.1',
7-
port: 5432,
8-
database: 'example',
9-
user: 'marcus',
10-
password: 'marcus',
11-
});
6+
const pool = new pg.Pool(config.db);
127

138
module.exports = (table) => ({
149
async query(sql, args) {

JavaScript/9-logger/http.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const http = require('node:http');
4+
const console = require('./logger.js');
45

56
const receiveArgs = async (req) => {
67
const buffers = [];

JavaScript/9-logger/logger.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const fs = require('node:fs');
44
const util = require('node:util');
55
const path = require('node:path');
6+
const config = require('./config.js');
67

78
const COLORS = {
89
info: '\x1b[1;37m',
@@ -68,4 +69,4 @@ class Logger {
6869
}
6970
}
7071

71-
module.exports = new Logger('./log');
72+
module.exports = new Logger(config.logPath);

JavaScript/9-logger/main.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
const fsp = require('node:fs').promises;
44
const path = require('node:path');
5-
const server = require('./ws.js');
65
const staticServer = require('./static.js');
76
const load = require('./load.js');
87
const db = require('./db.js');
98
const hash = require('./hash.js');
109
const logger = require('./logger.js');
10+
const config = require('./config.js');
11+
const server = require(`./${config.transport}.js`);
1112

1213
const sandbox = {
1314
console: Object.freeze(logger),
@@ -26,6 +27,6 @@ const routing = {};
2627
routing[serviceName] = await load(filePath, sandbox);
2728
}
2829

29-
staticServer('./static', 8000);
30-
server(routing, 8001);
30+
staticServer(config.staticPath, config.staticPort);
31+
server(routing, config.apiPort);
3132
})();

JavaScript/9-logger/static.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const http = require('node:http');
44
const path = require('node:path');
55
const fs = require('node:fs');
6+
const console = require('./logger.js');
67

78
module.exports = (root, port) => {
89
http.createServer(async (req, res) => {

0 commit comments

Comments
 (0)