-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·42 lines (33 loc) · 1.18 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
require('dotenv').config({path: "./vars/.env"});
const {PORT} = process.env;
const express = require("express");
const path = require("path");
const cors = require("cors");
const createError = require("http-errors");
const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");
const mongoose = require('mongoose')
const app = express();
app.use(express.static(path.join(__dirname, "public")));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
// app.use(logger("dev"));
app.use(cors());
app.options("*", cors()); // Attach 'Access-Control-Allow-Origin' to preflight
app.get('/', (req, res) => {
res.json({
success: true,
});
});
mongoose.connect(process.env.DB_URL).then(() => console.log('MongoDB connected...'))
.catch(error => console.log(error))
const authRouter = require("./src/routes/auth");
const questionRouter = require("./src/routes/question");
const adminRouter = require("./src/routes/admin")
app.use("/auth", authRouter);
app.use("/question", questionRouter);
app.use("/admin", adminRouter)
app.listen(PORT, () => {
console.log(`server is listening at localhost:${PORT}`);
});