/**
 * Module dependencies.
 */

var express = require('../../lib/express');

// Path to our public directory

var pub = __dirname + '/public';

// setup middleware

var app = express();
app.use(express.static(pub));

// Optional since express defaults to CWD/views

app.set('views', __dirname + '/views');

// Set our default template engine to "jade"
// which prevents the need for extensions
// (although you can still mix and match)
app.set('view engine', 'jade');

var posts = [{
	subject: "Hello",
	content: "Hi !"
},{
	subject: "World",
	content: "Hi !"
}];

app.get('/welcome', function(req, res) {
	res.render('index');
});

app.get('/post', function(req, res) {
	res.render('post', {
		posts: posts
	});
});

app.get('/1/post', function(req, res) {
	res.send(posts);
});

app.post('/1/post', function(req, res) {
	var subject;
	var content;
	
	if (typeof(req.body) === 'undefined') {
		subject = req.query.subject;
		content = req.query.content;
	}

	var post = {
		subject: subject,
		content: content
	};

	posts.push(post);

	res.send({ status: 'OK'});
});

app.delete('/1/post', function(req, res) {
	res.send("Delete a post");
});

app.put('/1/post/:postId', function(req, res) {
	var id = req.params.postId;

	res.send("Update a post: " + id);
});

// change this to a better error handler in your code
// sending stacktrace to users in production is not good
app.use(function(err, req, res, next) {
  res.send(err.stack);
});

/* istanbul ignore next */
if (!module.parent) {
  app.listen(3000);
  console.log('Express started on port 3000');
}

@@ -567,63 +567,1216 @@
 app.
-get('/welcome', function(req, res) %7B%0A%09res.render('index
+all('*', function(req, res, next)%7B%0A  if (!req.get('Origin')) return next();%0A  // use %22*%22 here to accept any origin%0A  res.set('Access-Control-Allow-Origin', '*');%0A  res.set('Access-Control-Allow-Methods', 'PUT');%0A  res.set('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type');%0A  // res.set('Access-Control-Allow-Max-Age', 3600);%0A  if ('OPTIONS' == req.method) return res.send(200);%0A  next();%0A%7D);%0A%0Aapp.get('/welcome', function(req, res) %7B%0A%09res.render('index');%0A%7D);%0A%0Aapp.get('/download', function(req, res) %7B%0A%09var events = require('events');%0A%09var workflow = new events.EventEmitter();%0A%0A%09workflow.outcome = %7B%0A%09%09success: false,%0A%09%7D;%0A%0A%09workflow.on('vaidate', function() %7B%0A%09%09var password = req.query.password;%0A%0A%09%09if (password === '123456') %7B%0A%09%09%09return workflow.emit('success');%0A%09%09%7D%0A%0A%09%09return workflow.emit('error');%0A%09%7D);%0A%0A%09workflow.on('success', function() %7B%0A%09%09workflow.outcome.success = true;%0A%09%09workflow.outcome.redirect = %7B %0A%09%09%09url: '/welcome'%0A%09%09%7D;%0A%09%09workflow.emit('response');%0A%09%7D);%0A%0A%09workflow.on('error', function() %7B%0A%09%09workflow.outcome.success = false;%0A%09%09workflow.emit('response');%0A%09%7D);%0A%0A%09workflow.on('response', function() %7B%0A%09%09return res.send(workflow.outcome);%0A%09%7D);%0A%0A%09return workflow.emit('vaidate
 ');%0A
@@ -1915,21 +1915,30 @@
 es.send(
+%7B
 posts
+: posts%7D
 );%0A%7D);%0A%0A

use EventEmitter