Skip to content

Instantly share code, notes, and snippets.

@leemartin
Created August 21, 2019 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leemartin/4cc931c94eca5abcd5419d31be42b906 to your computer and use it in GitHub Desktop.
Save leemartin/4cc931c94eca5abcd5419d31be42b906 to your computer and use it in GitHub Desktop.
A Dark Sky serverless function for Netlify
const fetch = require('node-fetch');
exports.handler = async (event, context) => {
try{
const latitude = event.queryStringParameters.latitude;
const longitude = event.queryStringParameters.longitude;
const response = await fetch(`https://api.darksky.net/forecast/${process.env.DARK_SKY_KEY}/${latitude},${longitude}`);
const data = await response.json();
return {
statusCode: 200,
body: JSON.stringify(data)
};
} catch (err) {
return {
statusCode: 500,
body: err.toString()
};
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment