Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
publication-server
Advanced tools
In order to be able to mount a WebSocket server on the same port as an Express server, we need to get the http server from the app so that we can expose it to the WebSocket server. As an example:
var express = require('express');
var PublicationServer = require('publication-server');
var app = express();
var server = require('http').createServer(app);
var errHandler = function(err) {
console.log(err.error);
};
var pubServer = new PublicationServer({
authFn: authenticationFunction,
mountPath: '/ws',
server,
errHandler
});
// ...
server.listen(process.env.PORT || '8080');
One plus of this server is that it can authenticate WebSocket requests via the
headers on the request. This is done in the authentication function that is
passed to the publication-server
constructor. The function should be as
follows:
function authenticationFunction(ws, done) {
// Logic checking the websocket headers, etc.
// ...
// We get the ID of the user that this connection is for as a String.
done(null, userId);
}
var pubSub = require('./path/to/initialized/server');
pubSub.publish('PublicationName', function() {
});
ready
Whenever a publication has finished publishing the initial documents that it
needs to send, it must mark itself as ready
. This is accomplished by calling
this.ready()
.
pubSub.publish('PublicationName', function() {
// Initial document publishing.
this.ready();
// Add future event handlers if desired.
});
If we encounter an error prior to marking a publication as ready
, we should
pass the error to this.error()
. This will call the registered error handler,
and pass the error along to the client.
pubSub.publish('PublicationName', function() {
this.error(new Error('failed to do something require'));
});
Errors passed to the error handler provided upon server initialization are objects with there properties:
error
: The original error that was reported by the publication.userId
: The ID of the user who was subscribing to the publication when the
error occurredextra
: Any extra information that was recorded - currently this is the
parameters that were provided to the publication.See publication-client for the client for this server.
FAQs
### Usage
The npm package publication-server receives a total of 20 weekly downloads. As such, publication-server popularity was classified as not popular.
We found that publication-server demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 30 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.