-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
61 lines (48 loc) · 1.6 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
54
55
56
57
58
59
60
61
const express = require("express");
const app = express();
const connectDB = require("./config/connect");
const bodyParser = require("body-parser");
const cors = require("cors");
require("dotenv").config();
// Routes Imports
const coursesRouter = require("./routes/courses.router");
const authorRouter = require("./routes/authors.test.route");
const userRouter = require("./routes/user.test.router");
const tweetsRouter = require("./routes/tweets.route");
const imageRouter = require("./routes/image.router");
const teacherRouter = require("./routes/teachers.routes");
const guideRouter = require("./routes/guides.routes");
app.use(express.static("./public"));
app.use(express.json());
app.use(bodyParser.json());
app.use(cors());
// enable CORS without external module
// app.use(function (req, res, next) {
// res.header("Access-Control-Allow-Origin", "*");
// res.header(
// "Access-Control-Allow-Headers",
// "Origin, X-Requested-With, Content-Type, Accept"
// );
// next();
// });
// Courses.route;
app.use("/api/v1/courses", coursesRouter);
// Authors route;
app.use("/api/v1/author", authorRouter);
// Tweets Route
app.use("/api/v1/tweets", tweetsRouter);
// User Router
app.use("/api/v1/users", userRouter);
// Image Router
app.use("/static/images/", imageRouter);
// Teacher Router
app.use("/api/v1/teacher", teacherRouter);
// Author Router
app.use("/api/v1/author", authorRouter);
// Guide Router
app.use("/api/v1/guide", guideRouter);
const port = process.env.PORT || 5000;
app.listen(port, async () => {
await connectDB(process.env.MONGO_URI);
console.log(`app is listening on port ${port}...`);
});