43 | );
44 | }
45 |
46 | export default App;
47 |
--------------------------------------------------------------------------------
/app.js:
--------------------------------------------------------------------------------
1 | const express = require("express")
2 | const cors = require("cors")
3 | const path = require("path")
4 | const mongoSanitize = require("express-mongo-sanitize")
5 |
6 | // start app
7 | const app = express()
8 |
9 | // Express port
10 | const port = process.env.PORT || 5000
11 | // const db = process.env.DATABASE
12 |
13 | // CORS
14 | app.use(cors())
15 |
16 | // Serve static files
17 | app.use(express.static(path.join(__dirname, 'client', 'build')))
18 |
19 | // Sanitize against NoSQL query injections
20 | app.use(mongoSanitize())
21 |
22 | // Setting up a route for our API
23 | app.get('/api/', (req, res) => {
24 | return res.status(200).json({
25 | status: "success"
26 | })
27 | })
28 |
29 | // Redirect back to index.html if urls do not match
30 | app.get("*", (req, res) => {
31 | res.sendFile(path.join(__dirname, "client/build", "index.html"))
32 | })
33 |
34 | // Database
35 | // mongoose
36 | // .connect(db, {
37 | // useNewUrlParser: true,
38 | // useCreateIndex: true,
39 | // useFindAndModify: false,
40 | // useUnifiedTopology: true,
41 | // })
42 | // .then(() => {
43 | // console.log("Database is connected.")
44 | // })
45 | // .catch((err) => {
46 | // console.log("Database connection was unsuccessful.")
47 | // console.log(err)
48 | // process.exit(1)
49 | // })
50 |
51 | app.listen(port, () => {
52 | console.log(`Listening on port ${port}`)
53 | })
54 |
55 |
--------------------------------------------------------------------------------
/client/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |