-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
43 lines (33 loc) · 963 Bytes
/
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 app = express();
const bodyParser = require("body-parser");
require("dotenv").config();
app.use(bodyParser.urlencoded({ extended: false }));
// parse application/json
app.use(bodyParser.json());
//importing db-connection query
const pool = require("./models/dbCon");
pool
.connect()
.then((row) => {
console.log("db is connected :", row._connected);
})
.catch((err) => {
throw err;
});
//for cors error
const cors = require("cors");
const corsOptions = {
origin: "*",
credentials: true,
methods: ["GET", "POST"],
allowedHeaders: ["Content-Type", "Access-Control-Allow-Headers"],
};
app.use(cors({ origin: "*" }));
const AllGetROutes = require("./routes/users/gets");
const AllPostRoutes = require("./routes/users/posts");
const AuthRoutes = require("./routes/users/auth");
app.use("/get", AllGetROutes);
app.use("/post", AllPostRoutes);
app.use("/auth", AuthRoutes);
app.listen(8081);