-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
68 lines (52 loc) · 1.89 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const express = require('express');
const mongoose = require('mongoose');
const routes = require('./routes');
const passport = require("passport");
const bodyParser = require('body-parser');
// const config = require("./config.json");
const stripe = require("stripe")(process.env.REACT_APP_STRIPE_KEY);
require('dotenv').config()
const app = express();
const PORT = process.env.PORT || 8001;
app.use(express.urlencoded({ extended: false}));
app.use(express.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(require("body-parser").text());
if(process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
}
mongoose.connect(process.env.MONGODB_URI || "mongodb://localhost/enatomy", { useNewUrlParser: true }, console.log(mongoose.connection.readyState));
////SETTING UP PASSPORT START---------------------------------------------------
// app.use(require('serve-static')(__dirname + '/../../public'));
app.use(require('cookie-parser')());
app.use(require('body-parser').urlencoded({ extended: true }));
app.use(require('express-session')({
secret: 'keyboard cat',
resave: true,
saveUninitialized: true
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(routes);
////SETTING UP PASSPORT END---------------------------------------------------
////SETTING UP PASSPORT END---------------------------------------------------
app.post("/charge/:amount/", async (req, res) => {
// let amount = parseInt(req.params.amount, 10)
// console.log(amount)
console.log(req.params.amount)
try {
let {status} = await stripe.charges.create({
amount: req.params.amount,
currency: "usd",
description: "Enatomy charge",
source: req.body
});
res.json({status});
} catch (err) {
res.status(500).end();
console.log("status code 500")
}
});
app.listen(PORT, () => {
console.log('Running on port:', PORT)
})