mirror of https://github.com/pelias/api.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
520 B
24 lines
520 B
10 years ago
|
|
||
|
function middleware(req, res, next){
|
||
|
|
||
|
// store old json function
|
||
|
var json = res.json.bind(res);
|
||
|
|
||
|
// replace with jsonp aware function
|
||
|
res.json = function( data ){
|
||
|
|
||
|
// jsonp
|
||
|
if( req.query && req.query.callback ){
|
||
|
res.header('Content-type','application/javascript');
|
||
|
return res.send( req.query.callback + '('+ JSON.stringify( data ) + ');' );
|
||
|
}
|
||
|
|
||
|
// regular json
|
||
|
res.header('Content-type','application/json');
|
||
|
return json( data );
|
||
|
};
|
||
|
|
||
|
next();
|
||
|
}
|
||
|
|
||
|
module.exports = middleware;
|