Last active
April 23, 2017 18:24
-
-
Save ColeTownsend/f87f764be7acf31044fc6deba14fab64 to your computer and use it in GitHub Desktop.
Post module for Micro Stripe API
This file contains 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
require('dotenv').config(); // we need our dotenv stuff | |
// https://github.com/romuloalves/micro-post/blob/master/src/index.js | |
module.exports = exports = function (fn) { | |
return (req, res) => { | |
res.setHeader('Access-Control-Request-Method', 'POST, GET') | |
res.setHeader("Access-Control-Allow-Credentials", "true"); | |
res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization"); | |
// set this with your own URL | |
res.setHeader('Access-Control-Allow-Origin', process.env.STRIPE_ALLOW_DOMAIN); | |
const {method} = req | |
if (method === 'OPTIONS') { | |
return {} | |
} | |
if (method === 'GET') { | |
return {message: 'The Stripe charge server is up and running!', timestamp: new Date().toISOString()} | |
} | |
if (method === 'POST') { | |
return fn(req, res) | |
} | |
else { | |
res.writeHead(405) | |
res.end('Method Not Allowed') | |
return | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment