Skip to content

Instantly share code, notes, and snippets.

@cahlan
Created October 17, 2013 16:10
Show Gist options
  • Save cahlan/7027693 to your computer and use it in GitHub Desktop.
Save cahlan/7027693 to your computer and use it in GitHub Desktop.
var messages = [{text: 'hi there'}];
var express = require('express');
var app = express();
app.configure(function() {
app.use(express.bodyParser());
app.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'OPTIONS, GET, POST');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
next();
});
});
app.get('/', function(req, res) {
res.type('application/json');
res.setHeader('Access-Control-Allow-Origin', '*');
res.end(JSON.stringify(messages));
});
app.post('/', function(req, res) {
console.log(req.body);
messages.push(req.body);
res.send(req.body);
});
app.listen(8888);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment