Created
July 31, 2012 06:02
-
-
Save diorahman/3214161 to your computer and use it in GitHub Desktop.
CORS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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