-
Notifications
You must be signed in to change notification settings - Fork 26
/
app.js
54 lines (44 loc) · 1.23 KB
/
app.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
const express = require("express")
const cors = require("cors")
const path = require("path")
const mongoSanitize = require("express-mongo-sanitize")
// start app
const app = express()
// Express port
const port = process.env.PORT || 5000
// const db = process.env.DATABASE
// CORS
app.use(cors())
// Serve static files
app.use(express.static(path.join(__dirname, 'client', 'build')))
// Sanitize against NoSQL query injections
app.use(mongoSanitize())
// Setting up a route for our API
app.get('/api/', (req, res) => {
return res.status(200).json({
status: "success"
})
})
// Redirect back to index.html if urls do not match
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "client/build", "index.html"))
})
// Database
// mongoose
// .connect(db, {
// useNewUrlParser: true,
// useCreateIndex: true,
// useFindAndModify: false,
// useUnifiedTopology: true,
// })
// .then(() => {
// console.log("Database is connected.")
// })
// .catch((err) => {
// console.log("Database connection was unsuccessful.")
// console.log(err)
// process.exit(1)
// })
app.listen(port, () => {
console.log(`Listening on port ${port}`)
})