Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

removed old form example

  • Loading branch information...
commit 06db11cd610fd92e13360c65acb7c5e6f064a9ff 1 parent 125421e
TJ Holowaychuk tj authored
Showing with 0 additions and 79 deletions.
  1. +0 −79 examples/form/app.js
79 examples/form/app.js
View
@@ -1,79 +0,0 @@
-/**
- * Module dependencies.
- */
-
-var express = require('../../');
-
-var app = module.exports = express();
-
-// Here we use the bodyDecoder middleware
-// to parse urlencoded request bodies
-// which populates req.body
-app.use(express.bodyParser());
-
-// The methodOverride middleware allows us
-// to set a hidden input of _method to an arbitrary
-// HTTP method to support app.put(), app.del() etc
-app.use(express.methodOverride());
-
-// Required by session
-app.use(express.cookieParser());
-
-// Required by req.flash() for persistent
-// notifications
-app.use(express.session({ secret: 'keyboard cat' }));
-
-app.get('/', function(req, res){
- // get ?name=foo
- var name = req.param('name') || '';
-
- // Switch the button label based if we have a name
- var label = name ? 'Update' : 'Save';
-
- // Buffer all flash messages.
- // Typically this would all be done in a template
- // however for illustration purposes we iterate
- // here.
-
- // The messages in req.flash() persist until called,
- // at which time they are flushed from the session
- var msgs = '<ul>',
- flash = req.flash();
- Object.keys(flash).forEach(function(type){
- flash[type].forEach(function(msg){
- msgs += '<li class="' + type + '">' + msg + '</li>';
- });
- });
- msgs += '</ul>';
-
- // If we have a name, we are updating,
- // so add the hidden _method input
- res.send(msgs
- + '<form method="post">'
- + (name ? '<input type="hidden" value="put" name="_method" />' : '')
- + 'Name: <input type="text" name="name" value="' + name + '" />'
- + '<input type="submit" value="' + label + '" />'
- + '</form>');
-});
-
-app.post('/', function(req, res){
- if (req.body.name) {
- // Typically here we would create a resource
- req.flash('info', 'Saved ' + req.body.name);
- res.redirect('/?name=' + req.body.name);
- } else {
- req.flash('error', 'Error: name required');
- res.redirect('/');
- }
-});
-
-app.put('/', function(req, res){
- // Typically here we would update a resource
- req.flash('info', 'Updated ' + req.body.name);
- res.redirect('/?name=' + req.body.name);
-});
-
-if (!module.parent) {
- app.listen(3000);
- console.log('Express started on port 3000');
-}
Please sign in to comment.
Something went wrong with that request. Please try again.