forked from NikhitaBarat/celuxe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
49 lines (37 loc) · 1.17 KB
/
server.js
File metadata and controls
49 lines (37 loc) · 1.17 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
const express = require('express')
const mongoose = require('mongoose')
const dotenv = require('dotenv')
const cors = require('cors')
dotenv.config()
const eventRoute = require('./routes/events.routes')
const newsRoute = require('./routes/news.routes')
const pantryRoute = require('./routes/capacity.routes')
const graphRoute = require('./graphql/query')
const path = require('path')
// configuration
const PORT = process.env.PORT || 4000
const app = express()
// middleware
app.use(express.json())
app.use(cors())
// database connections
mongoose.connect(process.env.DATABASE_URL)
const db = mongoose.connection
db.once('open', () => {
console.log('Database is connected')
})
// routes
app.use('/api/event', eventRoute)
app.use('/api/news', newsRoute)
app.use('/api/capacity', pantryRoute)
app.use('/graphql', graphRoute)
app.use(express.static(path.join(__dirname, "./client/build")))
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, './client/build', 'index.html'))
})
// app.get('/', (req, res) => {
// res.send('Server route is working perfectly')
// })
app.listen(PORT, (req, res) => {
console.log(`Server is running at http://localhost:${PORT}`)
})