Skip to content

Commit

Permalink
add debug statement
Browse files Browse the repository at this point in the history
  • Loading branch information
butlerx committed Feb 21, 2018
1 parent 616ba39 commit ef64451
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 7 deletions.
17 changes: 14 additions & 3 deletions lib/command.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
const localhost = host =>
process.getuid() === 0 && (host === 'localhost' || host === '0.0.0.0' || host === '127.0.0.1');
process.getuid() === 0 &&
(host === 'localhost' || host === '0.0.0.0' || host === '127.0.0.1');

export default ({ request: { headers }, client: { conn } }, { user, host, port, auth }) => ({
export default (
{ request: { headers }, client: { conn } },
{ user, host, port, auth },
) => ({
args: localhost(host)
? ['login', '-h', conn.remoteAddress.split(':')[3]]
: ['ssh', address(headers, user, host), '-p', port, '-o', `PreferredAuthentications=${auth}`],
: [
'ssh',
address(headers, user, host),
'-p',
port,
'-o',
`PreferredAuthentications=${auth}`,
],
user: localhost(host) || user !== '' || user.includes('@'),
});

Expand Down
1 change: 1 addition & 0 deletions lib/emitter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class WeTTy extends EventEmitter {
auth,
port,
});
this.emit('debug', `sshUser: ${sshUser}, args: ${args}`);
if (sshUser) {
term.spawn(socket, args);
} else {
Expand Down
3 changes: 2 additions & 1 deletion lib/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ export default class {
})
.on('spawn', ({ msg }) => logger.info(msg))
.on('connection', ({ msg, date }) => logger.info(`${date} ${msg}`))
.on('server', ({ msg }) => logger.info(msg));
.on('server', ({ msg }) => logger.info(msg))
.on('debug', msg => logger.debug(msg));
return wetty.start(
{
user: sshuser,
Expand Down
12 changes: 10 additions & 2 deletions lib/logger.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@ const logger = createLogger({
colorize({ all: true }),
label({ label: 'Wetty' }),
timestamp(),
printf(info => `${info.timestamp} [${info.label}] ${info.level}: ${info.message}`),
printf(
info =>
`${info.timestamp} [${info.label}] ${info.level}: ${info.message}`,
),
),
transports: [new transports.Console({ handleExceptions: true })],
transports: [
new transports.Console({
level: process.env.NODE_ENV === 'development' ? 'debug' : 'info',
handleExceptions: true,
}),
],
});

export default logger;
1 change: 1 addition & 0 deletions lib/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import events from './emitter.mjs';
const pubDir = path.join(__dirname, '..', 'public');

export default function createServer(port, { key, cert }) {
events.emit('debug', `key: ${key}, cert: ${cert}, port: ${port}`);
const app = express();
const wetty = (req, res) => res.sendFile(path.join(pubDir, 'index.html'));
app
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"main": "index.js",
"scripts": {
"lint": "eslint .",
"lint": "eslint --ext .js,.mjs .",
"build": "webpack",
"start": "node .",
"dev":
Expand Down

0 comments on commit ef64451

Please sign in to comment.