doc: add express, cors, and stripe along with middleware and routes to index.js

This commit is contained in:
Leon Xu
2022-05-07 14:42:13 -07:00
parent 8ecc8ef409
commit 4831ae523c
+24 -7
View File
@@ -1,9 +1,26 @@
const functions = require("firebase-functions");
const express = require("express");
const cors = require("cors");
const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY);
// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions
//
// exports.helloWorld = functions.https.onRequest((request, response) => {
// functions.logger.info("Hello logs!", {structuredData: true});
// response.send("Hello from Firebase!");
// });
// App Config
const app = express();
// Middleware
app.use(cors({ origin: true }));
app.use(express.json());
// API Routes
app.post("/paymens/create", async (req, res) => {
const total = request.query.total;
const paymentIntent = await stripe.paymentIntents.create({
amount: total, // subunits of the currency
currency: "usd",
});
res.status(201).send({
clientSecret: paymentIntent.client_secret,
});
});
// Listen command
exports.api = functions.https.onRequest(app);