-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
62 lines (50 loc) · 1.75 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
// Note: This file is for deployment only
const express = require('express');
const path = require('path');
const http = require('http');
const https = require('https');
const fs = require('fs');
// See your keys here: https://dashboard.stripe.com/account/apikeys
const Stripe = require('stripe');
const app = express();
const PORT = process.env.PORT || 5000;
const BASE_URL = process.env.REACT_APP_SERVER_BASE_URI;
app.use(express.static(path.join(__dirname, 'build')));
app.get('/*', function (req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
// Make sure domain name is updated below
var key_url = '/etc/letsencrypt/live/bizbuz.design/privkey.pem';
var cert_url = '/etc/letsencrypt/live/bizbuz.design/fullchain.pem';
var options = {};
app.get('/stripe/payment-intent', async (req, res) => {
console.log('in stripe intent');
const stripe = Stripe(
process.env.NODE_ENV === 'production' && req.type !== 'test'
? process.env.REACT_APP_STRIPE_PUBLIC_KEY_LIVE
: process.env.REACT_APP_STRIPE_PUBLIC_KEY
);
const intent = stripe.paymentIntents.create({
amount: req.amount,
currency: 'usd',
});
res.json({ client_secret: intent.client_secret });
});
if (process.env.SUDO_USER != undefined) {
options['key'] = fs.readFileSync(key_url);
options['cert'] = fs.readFileSync(cert_url);
http
.createServer(function (req, res) {
res.writeHead(301, {
Location: 'https://' + req.headers['host'] + req.url,
});
res.end();
})
.listen(80);
https.createServer(options, app).listen(443);
} else {
options['key'] = fs.readFileSync('privkey.pem');
options['cert'] = fs.readFileSync('cert.pem');
app.listen(PORT);
https.createServer(options, app).listen(process.env.PORT + 1 || 443);
}