Node module to allow CQRS-ing with Meteor.
npm i --save meteor-wapi
var express = require("express");
var MongoClient = require("mongodb").MongoClient;
var MW = require("meteor-wapi");
var mongoUrl = process.env.MONGO_URL || "mongodb://localhost:3001/meteor";
MongoClient.connect(mongoUrl, function (err, db) {
var mw = new MW(db);
var optionalContext = {
prefix: "echo: "
};
mw.methods({
echo: function (string) {
return this.prefix + string;
}
}, optionalContext);
var app = express()
.use("/call", mw.getRouter())
.listen(process.env.PORT || 4000);
});
Creates a new MW instance.
db
MongoClient connection required: a mongodb connection, as returned (via callback) by theMongoClient.connect
method.
An MW instance.
Registers one or more remote methods (mimicking Meteor's API). The methods will
be invoked when the client POST
s a DDP method
message to the server.
Methods can either:
- throw an error
- return a value
- return a promise
If the method returns a value (or an eventually fulfilled promise), the client will receive the returned (or resolved) value in the DDP response message.
If the method throws (or returns an eventually rejected promise), the client
will receive the error in the DDP response message. If the error is an instance
of MW.Error
, its code and message will be used for the reply. Otherwise a
generic 500 INTERNAL SERVER ERROR
error will be used.
-
methodsMap
string-function dictionary required: a dictionary of functions (just like in Meteor). -
optionalContext
object optional: an optional object which will be mixed in with the execution context of the method (thethis
value).
Nothing.
Returns an express
router which listens for POST
ed DDP method
messages,
authenticates them and runs the appropriate methods.
None.
An express
router (to be used as argument to an express app use
method).
After cloning the repository and installing dependecies with npm install
:
- to run unit tests:
npm run unit-tests
- to run integration tests:
npm run integration-tests
(you need a running local mongo listening on port 27017)