Skip to content

Instantly share code, notes, and snippets.

@diorahman
Created July 31, 2012 06:02
Show Gist options
  • Save diorahman/3214161 to your computer and use it in GitHub Desktop.
Save diorahman/3214161 to your computer and use it in GitHub Desktop.
CORS
$.ajax({
url: 'http://beda.dio.jit.su/ping',
contentType: 'application/json',
dataType: 'json',
data: {},
type: 'POST',
beforeSend: function(xhr) {
xhr.setRequestHeader('x-Token-Sns','Test'); // header key name case-insensitive
}
})
.success(function (res) {
$('#content').html(JSON.stringify(res));
})
.error(function (err) {
console.log(err);
});
exports = module.exports = function(options){
options = options || {}
return function raw(req, res, next) {
res.header("Access-Control-Allow-Origin", "*")
res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS')
res.header("Access-Control-Allow-Headers", 'X-Requested-With, X-Token-Sns, X-Method-Type, Content-Type')
next()
}
};
var express = require('express')
var server = express.createServer()
server.use(require('./p')())
server.get('/ping', function(req, res){
res.send({reply : "pong"})
})
server.listen(8000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment