-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (36 loc) · 1.46 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
const express = require("express");
const dotenv = require("dotenv");
const cors = require("cors");
const mongoose = require("mongoose");
const VerifyToken = require("./middlewares/VerifyToken");
dotenv.config();
const app = express();
const PORT = process.env.PORT || 3001;
app.use(cors()); // Allow cross-origin requests (for frontend to communicate with backend on different ports/address)
app.use(express.json()); // Parses incoming JSON requests and uts the parsed data in req
app.use(express.urlencoded({ extended: true })); // Parses incoming requests with urlenconded payloads
mongoose.connect(process.env.MONGO_URI, () => {
console.log("connected to DB!√");
});
/**
* Uses the VerifyToken middleware to protect the data route
* Use the VerifyToken to protect all routes that require authentication
*/
app.use("/data", VerifyToken, require("./routes/users"));
app.get("/", (req, res) => {
// Default route: Unprotected
res.send("Express Auth Temp!!");
});
const usersRouter = require("./routes/users");
const childrenRouter = require("./routes/children");
const tasksRouter = require("./routes/tasks");
const postsRouter = require("./routes/posts");
const verificationRouter = require("./routes/verification");
app.use("/users", usersRouter);
app.use("/children", childrenRouter);
app.use("/tasks", tasksRouter);
app.use("/posts", postsRouter);
app.use("/verification", verificationRouter);
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});