Created
March 18, 2019 05:08
-
-
Save banyudu/bad9939c6f45b652952671bb67e72593 to your computer and use it in GitHub Desktop.
Lambda code of cors service
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
import axios from 'axios' | |
export const get = async (event: any, context: any, callback: any) => { | |
const parameters = Object.keys(event.queryStringParameters) | |
if (parameters.length !== 1) { | |
callback(null, { | |
statusCode: 400 | |
}) | |
} | |
const url = parameters[0] | |
try { | |
const result = await axios.get(url) | |
callback(null, { | |
statusCode: 200, | |
headers: { | |
'content-type': result.headers['content-type'] || 'text/html; charset=utf-8', | |
'Access-Control-Allow-Origin': 'https://banyudu.com', | |
'Cache-Control': 'public, max-age=3600' | |
}, | |
body: result.data | |
}) | |
} catch (error) { | |
console.error(error) | |
throw error | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment