0.1.0 • Published 11 years ago
Share package A lightweight (stupid) solution to save beta forms. Installation npm install beta-middleware --saveIntegration as route var beta = require('beta-middleware');
app.get('/beta/beta.js', beta.provideClientAPI());
app.post('/beta/:type', beta.route(function(data, callback) {
mongoose.save(data, callback);
}));Option Default value Description saveHeaders true Includes req.headers into the persistent information. saveCookies false Includes req.cookies into the persistent information. saveSignedCookies false Includes req.signedCookies into the persistent information. saveSession false Includes req.session into the persistent information.
Integration as middleware var beta = require('beta-middleware');
app.get('/beta/beta.js', beta.provideClientAPI());
app.post('/beta/:type', beta.middleware(function(data, callback) {
mongoose.save(data, callback);
}), function(req, res) {
res.render('registration_successful');
});Additional options (+ save options from above):
Option Default value Description successLocation - Redirect URL when information are saved successfully.If defined the Location will set with status code 201. Status 201 without any data will be returned otherwise. errorLocation - Redirect URL when an error occurred.If defined the Location will set with status code 301. Next middleware will be called with an error otherwise.
Full REST service based on Express var express = require('express'),
mongoose = require('mongoose'),
beta = require('beta-middleware/integration/express-mongoose');
app.use('/beta', beta(express, mongoose, {
readSecret: 'sWZGTh7GiCXTuE3qJHmz5B3tNDwdV3Fb', // replace this
deleteSecret: 'MNI2kToBnuIhjFk26IvVBrz83UFnfzcw' // secret keys!
}));Route Status code POST /beta201 when successful301 when an error occurs GET /beta[?filter]filter example: ?query.abtesting=42200 when successful, json array401 when unauthorized403 when secret doesn't match500 for other errors GET /beta/:id200 when successful, json object401 when unauthorized403 when secret doesn't match404 if id could not be found500 for other errors DELETE /beta/:id204 when successful deleted401 when unauthorized403 when secret doesn't match404 if id could not be found500 for other errors