Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public start(opts: GatewayStartOptions) {
if (this.started) {
this.warn('Gateway is already started');
return;
}
const { serviceCall } = opts;
validateServiceCall(serviceCall);
this.server = new RSocketServer({
serializers: JsonSerializers,
getRequestHandler: (socket) => {
return {
requestResponse: (payload: RsocketEventsPayload) =>
requestResponse(payload, serviceCall, this.requestResponse),
requestStream: (payload: RsocketEventsPayload) => requestStream(payload, serviceCall, this.requestStream),
};
},
transport: this.transport,
});
this.server.start();
// console.log('Gateway started on port: ' + this.port);
this.started = true;
}
async function run(options) {
const serverOptions = {
host: options.host,
port: options.port,
};
if (!isClient) {
const deferred = new Deferred();
const server = new RSocketServer({
getRequestHandler: socket => {
runOperation(socket, options);
return new SymmetricResponder();
},
transport: getServerTransport(options.protocol, serverOptions),
});
server.start();
console.log(`Server started on ${options.host}:${options.port}`);
return deferred.getPromise();
} else {
console.log(`Client connecting to ${options.host}:${options.port}`);
// $FlowFixMe
const socket: ReactiveSocket = await connect(
options.protocol,
serverOptions,
console.error(`Error opening server on port ${port}`, 'server');
reject(err);
})
.on('listening', () => {
console.debug(
`${
sslConfig ? 'Secure' : 'Certificate'
} server started on port ${port}`,
'server',
);
server.emit('listening', port);
resolve(rsServer);
});
return transportServer;
};
rsServer = new RSocketServer({
getRequestHandler: sslConfig
? this._trustedRequestHandler
: this._untrustedRequestHandler,
transport: new RSocketTCPServer({
port: port,
serverFactory: serverFactory,
}),
});
rsServer && rsServer.start();
});
}
console.error(`Error opening server on port ${port}`, 'server');
reject(err);
})
.on('listening', () => {
console.debug(
`${
sslConfig ? 'Secure' : 'Certificate'
} server started on port ${port}`,
'server',
);
server.emit('listening', port);
resolve(rsServer);
});
return transportServer;
};
rsServer = new RSocketServer({
getRequestHandler: sslConfig
? this._trustedRequestHandler
: this._untrustedRequestHandler,
transport: new RSocketTCPServer({
port: port,
serverFactory: serverFactory,
}),
});
rsServer && rsServer.start();
});
}
async function run(options) {
const deferred = new Deferred();
const serverOptions: ServerOptions = {
host: options.host,
port: options.port,
};
let server = new RSocketServer({
getRequestHandler: payload => {
return new Responder();
},
transport: getTransport(options.protocol, serverOptions),
});
server.start();
console.log(`Server started on ${options.host}:${options.port}`);
return deferred.getPromise();
}
}
case '/greeting/failing/one': {
responseData = getFailingOneResponse(data);
break;
}
case '/greeting/pojo/one': {
responseData = { text: getTextResponseSingle(data.text) };
break;
}
}
resolve({ data: responseData })
}, 100);
});
};
const server = new RSocketServer({
getRequestHandler: (socket) => {
return {
requestResponse({ data, metadata: { q } }) {
return new Single(subscriber => {
requestResponseHandler(data, q).then(response => subscriber.onComplete(response));
subscriber.onSubscribe();
});
},
requestStream({ data, metadata: { q } }) {
return new Flowable(subscriber => {
let index = 0;
let isStreamCanceled = false;
subscriber.onSubscribe({
cancel: () => { isStreamCanceled = true },
request: n => {
if (q.includes('/one')) {