mirror of https://github.com/pelias/api.git
Peter Johnson
10 years ago
4 changed files with 52 additions and 43 deletions
@ -0,0 +1,10 @@
|
||||
|
||||
function middleware(req, res, next){ |
||||
res.header('Access-Control-Allow-Origin', '*'); |
||||
res.header('Access-Control-Allow-Methods', 'GET'); |
||||
res.header('Access-Control-Allow-Headers', 'X-Requested-With,content-type'); |
||||
res.header('Access-Control-Allow-Credentials', true); |
||||
next(); |
||||
} |
||||
|
||||
module.exports = middleware; |
@ -0,0 +1,12 @@
|
||||
|
||||
var pkg = require('../package'); |
||||
|
||||
function middleware(req, res, next){ |
||||
res.header('Charset','utf8'); |
||||
res.header('Cache-Control','public,max-age=60'); |
||||
res.header('Server', 'Pelias/'+pkg.version); |
||||
res.header('X-Powered-By', 'mapzen'); |
||||
next(); |
||||
} |
||||
|
||||
module.exports = middleware; |
@ -0,0 +1,24 @@
|
||||
|
||||
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; |
Loading…
Reference in new issue