Skip to content

Commit

Permalink
karmen authenticator api integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Gottfried committed May 14, 2020
1 parent 9310d21 commit 716a67f
Show file tree
Hide file tree
Showing 13 changed files with 832 additions and 117 deletions.
4 changes: 2 additions & 2 deletions client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ class Channel extends Object {
headers: ireq.headers,
search: ireq.search,
}
if (requestParameters['headers'].host) {
delete requestParameters.headers['host'];
if (requestParameters.headers.host) {
delete requestParameters.headers.host;
}
info(` > ${this.id}: ${ireq.method} ${ireq.url} -> ${forwardToUrl.toString()}`);
this.url = forwardToUrl.toString();
Expand Down
25 changes: 14 additions & 11 deletions client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,14 @@ function Client(key, forwardTo) {
this.connect = function connect(serverUrl, config={forwardTo:forwardTo}) {
return new Promise((resolve, reject) => {
const connection = this.wsProxy.connect(serverUrl, config);
connection.on('error', function clientError(err) {
error(`An error occured while connecting to ${serverUrl}.
connection
.on('error', function clientError(err) {
error(`An error occured while connecting to ${serverUrl}.
Error: ${err}.
Make sure the server is running on the address port specified?
`);
})
.on('open', function clientOnConnect() {
info(`Tunnel ${serverUrl} -> ${config.forwardTo} set up and ready.`);
})
.on('close', function clientOnClose() {
info('Connection closed, exitting.');
process.exit(1);
})
.on('error', reject)
.on('open', ()=> {
Expand Down Expand Up @@ -74,6 +68,15 @@ if (require.main == module) {
forwardTo: ${forwardTo}
`);

new Client(clientKey).connect(serverUrl, {requestTimeout: config.requestTimeout, forwardTo: forwardTo});

new Client(clientKey)
.connect(serverUrl, {requestTimeout: config.requestTimeout, forwardTo: forwardTo}).then((client) => {
client.wsProxy
.on('open', function clientOnConnect() {
info(`Tunnel ${serverUrl} -> ${config.forwardTo} set up and ready.`);
})
.on('close', function clientOnClose() {
info('Connection closed, exitting.');
})
.on('close', () => process.exit(1));
});
}
4 changes: 4 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ let CONFIG = {
server: {
host: val('ADDRESS', 'localhost'),
port: val('PORT', '8090'),
// authenticator config
// null - no authenticator (allow any key to pass)
// http(s)://... - a url for key-master APIs
keyServerUrl: val('AUTHENTICATOR', undefined),
},
client: {
key: val('KEY', 'client-1'),
Expand Down
Loading

0 comments on commit 716a67f

Please sign in to comment.