Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
backbone-server
Advanced tools
Creates a Backbone.Server object which interfaces between Backbone, Socket.IO and Express.
Backbone-Server creates a Server module which pulls together Backbone and Express to bring greater structure to your NodeJS applications.
Backbone.Server can be accessed just like any other Backbone module:
var Backbone = require('backbone-server'); // Note: Backbone-Server relies on the backbone npm package and is not required.
// Current defaults for Backbone.Server
var server = new Backbone.Server({
'express' : express.createServer(), // The actual server handling everything
'port' : 8000, // The port the server will run on
'public' : 'public', // The directory for static content
'routes' : {}, // For quick apps, basic routes you can configure upon instantiation
'socketio' : false, // If set to true, adds socketio support to the server
'views' : 'views', // The directory where views can be found
'view engine' : 'ejs' // The engine used to render views
});
Once you have added a Server, add routes just as you would with Express:
server.get('/post/:id', function(req, res) {
var id = req.params.id,
article = articles.get(id);
res.render('single', article);
});
server.post('/post', function(req, res) {
articles.add(req.params);
});
server.put('/post/:id', function(req, res) {
var article = article.get(req.params.id);
article.set(req.params);
});
server.delete('/post/:id', function(req, res) {
articles.remove(params.req.id);
});
To enable socket.io functionality, set the socketio
attribute to true
upon creation of your new Backbone.Server object:
var server = new Backbone.Server(
'socketio' : true // If set to true, Backbone.Server will enable socket.io functionality
});
This will create an instance of socket.io at the io
attribute of your new server object (server.io
). You can now add standard socket.io events using the bind
and receive
methods, like so:
// Socket.IO Functions
server.bind('connection', function() {
console.log("connected");
var Article = new Backbone.Model(),
Articles = new Backbone.Collection({
model: Article
});
// code to add records to Articles data
server.send('models', Articles.toJSON());
});
In your clientside application, you can receive commands from the server like so (note that backbone-server automatically provides a route to load Underscore and Backbone):
<script src="/backbone-server/backbone.js" type="text/javascript"></script>
<script src="/socket.io/socket.io.js" type="text/javascript"></script>
<script>
var socket = io.connect('http://localhost');
var Article = Backbone.Model.extend();
var Articles = Backbone.Collection.extend({
model: Article,
initialize: function() {
// Bind an event to notify when an article has been added to the server
this.bind('add', function(article) {
console.log("Article added!");
});
}
});
var articles = new Articles();
socket.on('models', function(data) {
articles.add(d); // queues the collection event ('articles added!');
});
</script>
To summarize, in the example above, we've created a Backbone.Server
which will push down server side models upon connection, and add them
to the client scripts Articles
collection.
Once you have created a server starting it is easy:
server.start();
###Target Express directly:
// server.express == Express
server.express
###Target Socket.io directly:
// server.io == socket.io
server.io
FAQs
Creates a Backbone.Server object which interfaces between Backbone, Socket.IO and Express.
We found that backbone-server demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.