-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
63 lines (52 loc) · 1.51 KB
/
server.js
File metadata and controls
63 lines (52 loc) · 1.51 KB
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
//Required files and libraries
require('dotenv').config();
const express = require('express');
const { connectToDb,getSubscription, getTransactionData } = require('./database/database');
const { userSignUp } = require('./routes/signup');
const { userLogin } = require('./routes/login');
const { checkoutStripe, refundStripe } = require('./src/stripe');
const app = express();
//port
const port = process.env.PORT || 3000;
//middlewares
app.use(express.json());
app.use(express.static(__dirname+'/public'));
//Connect to database and start the server
connectToDb((err) => {
if(!err){
app.listen(port,() => {
console.log('Server is Running Successfully at Port:',port);
});
}
else{
console.error(err);
}
});
//routes
app.get('/',(req,res) => {
res.sendFile(__dirname+'/public/login.html');
});
app.get('/signup',(req,res) => {
res.sendFile(__dirname+'/public/signup.html');
});
app.get('/subscription', (req,res) => {
res.sendFile(__dirname+'/public/subscription.html');
})
app.post('/api/signup', (req,res) => {
userSignUp(req,res);
});
app.post('/api/login', (req,res) => {
userLogin(req,res);
})
app.post('/api/subscription', (req,res) => {
getSubscription(req,res);
});
app.post('/api/checkout', (req,res) => {
checkoutStripe(req,res);
});
app.post('/api/transaction', (req,res) => {
getTransactionData(res);
});
app.delete('/api/refund', (req,res) => {
refundStripe(req,res);
});