-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
59 lines (45 loc) · 1.35 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
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const secret = process.env.stripe_secret;
const stripe = require ("stripe")(secret);
const routes = require('./routes.js');
const longpoll = require("express-longpoll")(app);
let data = {price: 0};
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.header("Access-Control-Allow-Methods", "GET, POST, DELETE, PATCH, PUT" );
next();
});
app.use(bodyParser.json());
app.use(routes);
app.post('/rg', (req, res, next) => {
const body = req.body.cartList;
console.log(body)
let total = 0;
total = body.reduce((prev, curr) => {
return prev+curr.itemPrice
}, total);
data.price = total;
res.send(data);
});
app.post('/button', (req, res, next) => {
console.log(req.body);
data.price = req.body.donation;
console.log(data.price)
res.send(data);
});
app.get('/confirm', (req, res, next) => {
console.log('you are in confirm')
console.log(data.price);
res.send(data);
});
app.post('/reset', (req, res, next) => {
data.price = 0;
});
longpoll.create("/poll");
longpoll.publish("/poll", data);
setInterval(() => longpoll.publish("/poll", data), 3000)
app.listen(process.env.PORT || 5000);
module.exports = app;