Created
October 4, 2021 17:25
-
-
Save liyasthomas/99dd8c244182c50f8fa392efc6fc06dd to your computer and use it in GitHub Desktop.
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 fetch from "node-fetch"; | |
const USERNAME = "hoppscotch"; | |
const REPOSITORY = "hoppscotch"; | |
exports.handler = async (event) => { | |
switch (event.httpMethod) { | |
case "GET": | |
try { | |
const commit_activity_response = await fetch( | |
`https://api.github.com/repos/${USERNAME}/${REPOSITORY}/stats/commit_activity` | |
); | |
const commit_activity = await commit_activity_response.json(); | |
return { | |
statusCode: 200, | |
headers: { | |
"Content-Type": "application/json", | |
"Access-Control-Allow-Origin": "*", | |
"Access-Control-Allow-Headers": | |
"Origin, X-Requested-With, Content-Type, Accept", | |
"Access-Control-Allow-Credentials": true, | |
"Access-Control-Allow-Methods": "GET", | |
}, | |
body: JSON.stringify( | |
{ | |
commit_activity, | |
}, | |
null, | |
2 | |
), | |
}; | |
} catch (e) { | |
return { statusCode: 500, body: e.toString() }; | |
} | |
default: | |
return { statusCode: 405, body: "Method Not Allowed" }; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment