Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function server() {
const opts = Object.assign({
perMessageDeflate: !!this.primus.options.compression,
maxPayload: this.primus.options.maxLength
}, this.primus.options.transport);
this.service = native.server;
let flags = 0;
if (opts.perMessageDeflate) {
flags |= uws.PERMESSAGE_DEFLATE;
if (opts.perMessageDeflate.serverNoContextTakeover === false) {
flags |= uws.SLIDING_DEFLATE_WINDOW;
}
}
const group = native.server.group.create(flags, opts.maxPayload);
let upgradeReq = null;
native.server.group.onConnection(group, (socket) => {
const spark = new this.Spark(
upgradeReq.headers, // HTTP request headers.
upgradeReq, // IP address location.
url.parse(upgradeReq.url).query, // Optional query string.
null, // We don't have an unique id.
upgradeReq, // Reference to the HTTP req.
socket // Reference to the socket.