Skip to content

Commit

Permalink
Add simple config
Browse files Browse the repository at this point in the history
  • Loading branch information
DemianParkhomenko committed Sep 14, 2023
1 parent 79b703a commit bef3fba
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
15 changes: 15 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
static: {
port: 8000,
},
server: {
port: 8001,
},
db: {
host: '127.0.0.1',
port: 5432,
database: 'example',
user: 'marcus',
password: 'marcus',
},
};
9 changes: 2 additions & 7 deletions src/db.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
'use strict';

const pg = require('pg');
const config = require('./config.js');

const pool = new pg.Pool({
host: '127.0.0.1',
port: 5432,
database: 'example',
user: 'marcus',
password: 'marcus',
});
const pool = new pg.Pool(config.db);

module.exports = (table) => ({
async query(sql, args) {
Expand Down
5 changes: 3 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const load = require('./load.js');
const db = require('./db.js');
const hash = require('./hash.js');
const logger = require('./logger.js');
const config = require('./config.js');

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

staticServer('./static', 8000);
server(routing, 8001);
staticServer('./static', config.static.port);
server(routing, config.server.port);
})();
2 changes: 1 addition & 1 deletion src/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ module.exports = (root, port) => {
})
.listen(port);

console.log(`Static on port ${port}`);
console.log(`Static on http://localhost:${port}/`);
};
1 change: 1 addition & 0 deletions src/static/client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

// TODO: move to config
const socket = new WebSocket('ws://127.0.0.1:8001/');

const scaffold = (structure) => {
Expand Down
2 changes: 1 addition & 1 deletion src/ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ module.exports = (routing, port) => {
});
});

console.log(`API on port ${port}`);
console.log(`API on http://localhost:${port}/`);
};

0 comments on commit bef3fba

Please sign in to comment.