-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
54 lines (44 loc) · 1.35 KB
/
index.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
require("dotenv").config();
const express = require("express");
const morgan = require('morgan')
const {pool} = require('./database/mysql')
const cors = require('cors')
const guestsRouter = require('./routes/guests')
const infoRouter = require('./routes/info')
const checkinRouter= require("./routes/checkin")
const paymentRouter = require("./routes/payment")
const rsvpRouter = require("./routes/rsvp")
const auth = require('./auth/auth')
const passport = require("./auth/passport")
const mongoClient = require('./database/mongo')
const PORT =
parseInt(process.argv[2]) || parseInt(process.env.PORT) || 3000;
const app = express()
app.use(cors())
app.use(morgan('combined'))
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(passport.initialize())
app.use('/guests', auth.require, guestsRouter)
app.use('/info', infoRouter)
app.use('/checkin',checkinRouter)
app.use('/rsvp', rsvpRouter)
app.post('/login', auth.login)
app.use('/payment',paymentRouter )
const startSQL = pool.getConnection()
.then((conn) => {
conn.ping();
console.log("pinged");
// app.listen(PORT ,()=> {
// console.log(`${PORT} started `)
// })
return conn;
})
.then((conn) => conn.release());
Promise.all([mongoClient.connect(), startSQL])
.then(([m,s])=> {
app.listen(PORT ,()=> {
console.log(`${PORT} started `)
})
})
.catch(e=> console.log)