Skip to content

Commit

Permalink
refactor: move router creation to helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
b-ma committed Jan 18, 2025
1 parent 8128f75 commit 0b08334
Show file tree
Hide file tree
Showing 10 changed files with 357 additions and 679 deletions.
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,13 @@
"dependencies": {
"@ircam/sc-utils": "^1.8.0",
"chalk": "^5.3.0",
"columnify": "^1.6.0",
"compression": "^1.7.1",
"express": "^4.19.2",
"clone-deep": "^4.0.1",
"fast-deep-equal": "^3.1.3",
"isomorphic-ws": "^5.0.0",
"keyv": "^4.5.4",
"keyv-file": "^0.3.1",
"lodash": "^4.17.21",
"merge-deep": "^3.0.3",
"pem": "^1.14.8",
"template-literal": "^1.0.4",
"uuid": "^9.0.1",
"ws": "^8.17.0"
},
Expand Down
66 changes: 1 addition & 65 deletions src/common/logger.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import chalk from 'chalk';
import columnify from 'columnify';

/**
* @private
Expand Down Expand Up @@ -43,69 +42,6 @@ const logger = {
console.error(chalk.red(msg));
},

clientConfigAndRouting(routes, config) {
if (!this.verbose) {
return;
}

const clientsConfig = config.app.clients;
const serverAddress = config.env.serverAddress;
const auth = config.env.auth;
const table = [];

for (let role in clientsConfig) {
const client = clientsConfig[role];

if (client.runtime === 'node') {
const line = {
role: `> ${role}`,
runtime: chalk.red(client.runtime),
path: `serverAddress: ${chalk.green(serverAddress)}`,
default: undefined,
auth: undefined,
};

table.push(line);
} else if (client.runtime === 'browser') {
const line = {
role: `> ${role}`,
runtime: chalk.red(client.runtime),
path: routes.find(r => r.role === role) ?
chalk.green(routes.find(r => r.role === role).path) :
chalk.red('no route defined'),
default: (client.default ? 'x' : undefined),
auth: auth && auth.clients.indexOf(role) !== -1 ? 'x' : undefined,
};

table.push(line);
}
}

console.log(``);
console.log(columnify(table, {
showHeaders: true,
minWidth: 6,
columnSplitter: ' | ',
config: {
default: { align: 'center' },
auth: { align: 'center' },
},
}));
console.log(``);

// check if a route is defined but not in config
if (clientsConfig) {
const configClientTypes = Object.keys(clientsConfig);
routes.forEach(r => {
if (configClientTypes.indexOf(r.role) === -1) {
console.log(`@warning: no client config found for route ${r.role}`);
}
});
} else {
console.log(`@warning: no config found for clients`);
}
},

ip(protocol, address, port) {
if (!this.verbose) {
return;
Expand Down Expand Up @@ -146,7 +82,7 @@ const logger = {
console.log(` ${name} ${chalk.red('errors')}`);
},

warnVersionDiscepancies(clientRole, clientVersion, serverVersion) {
warnVersionDiscrepancies(clientRole, clientVersion, serverVersion) {
console.warn(`
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Expand Down
Loading

0 comments on commit 0b08334

Please sign in to comment.