Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/christoph-jerolimov/beta-middleware
A lightweight (stupid) solution to save beta forms.
https://github.com/christoph-jerolimov/beta-middleware
Last synced: 28 days ago
JSON representation
A lightweight (stupid) solution to save beta forms.
- Host: GitHub
- URL: https://github.com/christoph-jerolimov/beta-middleware
- Owner: christoph-jerolimov
- Created: 2014-08-11T00:22:38.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-08-11T01:33:26.000Z (over 10 years ago)
- Last Synced: 2024-11-25T12:16:12.276Z (28 days ago)
- Language: JavaScript
- Size: 148 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## A lightweight (stupid) solution to save beta forms.
### Installation
npm install beta-middleware --save
### Integration as route
```javascript
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
```javascript
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
```javascript
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 /beta` | 201 when successful
301 when an error occurs |
| `GET /beta[?filter]`
filter example: ?query.abtesting=42 | 200 when successful, json array
401 when unauthorized
403 when secret doesn't match
500 for other errors |
| `GET /beta/:id` | 200 when successful, json object
401 when unauthorized
403 when secret doesn't match
404 if id could not be found
500 for other errors |
| `DELETE /beta/:id` | 204 when successful deleted
401 when unauthorized
403 when secret doesn't match
404 if id could not be found
500 for other errors |