0.1.0 • Published 10 years ago

beta-middleware v0.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
10 years ago

A lightweight (stupid) solution to save beta forms.

Installation

npm install beta-middleware --save

Integration 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);
}));
OptionDefault valueDescription
saveHeaderstrueIncludes req.headers into the persistent information.
saveCookiesfalseIncludes req.cookies into the persistent information.
saveSignedCookiesfalseIncludes req.signedCookies into the persistent information.
saveSessionfalseIncludes 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):

OptionDefault valueDescription
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!
}));
RouteStatus 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
0.1.0

10 years ago

0.0.1

10 years ago