
Security News
Socket Releases Free Certified Patches for Critical vm2 Sandbox Escape
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.
@diaspora/plugin-server
Advanced tools
A package to add RESTful APIs to Express with Diaspora
In order to run this plugin, you need to install both the Diaspora Server plugin & Diaspora itself.
npm install @diaspora/plugin-server @diaspora/diaspora
import { Diaspora } from '@diaspora/diaspora';
import { ExpressApiGenerator } from '@diaspora/plugin-server' );
import express = require( 'express' );
const app = express();
/* Configure Diaspora first: create your data sources, declare your models, etc... */
Diaspora.createNamedDataSource( /* ... */ );
Diaspora.declareModel( 'PhoneBook', /* ... */);
// Generates the API handler class
const expressApiGenerator = new ExpressApiGenerator({
models: {
PhoneBook: {
singular: 'PhoneBook',
plural: 'PhoneBooks',
middlewares: { /* ... */ },
},
},
});
// Use the middleware to handle your requests
app.use( '/api', expressApiGenerator.middleware );
In the hash models, you can select which models you want to expose. You can use regular expressions, minimatch or plain text matching:
const expressApiGenerator = new ExpressApiGenerator({
models: {
'/ab?c\\d+/': {} // Regex, will match ac1, abc1, abc09
'Qux*': {} // Minimatch, will match Qux, QuxFoo, etc etc
PhoneBook: {} // Plain text matching
},
});
In your model configuration, you can use following middlewares:
| Action | Middleware functions (singular API) | Middleware functions (plural API) |
|---|---|---|
| Insert | post, insert, insertOne | post, insert, insertMany |
| Find | get, find, findOne | get, find, findMany |
| Update | patch, update, updateOne | patch, update, updateMany |
| Replace | put, update, replaceOne | put, update, replaceMany |
| Delete | delete, deleteOne | delete, deleteMany |
Each middleware will be called as a standard Express middleware (eg with req, res & next). You can use them to customize the behavior of Diaspora Server.
Diaspora Server uses the same Diaspora module than your app, both sharing models & the web server.
For each requests below, the server may respond:
/api/foo/66b72592-b1e2-4229-82b2-c94b475c9135| Action | HTTP Verb | Additionnal possible responses |
|---|---|---|
| Insert | POST | 201 Created on success, 400 Bad request if validation failed |
| Find | GET | 200 OK on success |
| Update (diff) | PUT | 200 OK on success, 400 Bad request if validation failed, 405 Method Not Allowed if no where clause |
| Update (replace) | PATCH | 200 OK on success, 400 Bad request if validation failed, 405 Method Not Allowed if no where clause |
| Delete | DELETE | 204 No Content if no errors occured |
The documentation will be available at https://diaspora-server.ithoughts.io/
Inspired by this tutorial
FAQs
A webserver module for Diaspora
We found that @diaspora/plugin-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.

Security News
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.

Research
Five malicious NuGet packages impersonate Chinese .NET libraries to deploy a stealer targeting browser credentials, crypto wallets, SSH keys, and local files.

Security News
pnpm 11 turns on a 1-day Minimum Release Age and blocks exotic subdeps by default, adding safeguards against fast-moving supply chain attacks.