-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (25 loc) · 837 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
const express = require("express");
const app = express();
const mongoose = require("mongoose");
const dotenv = require("dotenv");
const cors = require("cors");
app.use(cors());
dotenv.config();
const port = process.env.PORT;
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "*");
res.header("Access-Control-Expose-Headers", "auth-token");
next();
});
mongoose.connect(
process.env.ATLAS,
{ useNewUrlParser: true, useUnifiedTopology: true },
() => console.log("Connected to database")
);
const authRoute = require("./routes/auth");
const postsRoute = require("./routes/posts");
app.use(express.json());
app.use("/api/users", authRoute);
app.use("/api/posts", postsRoute);
app.listen(port, () => console.log(`Server listening on port ${port}`));