-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
48 lines (38 loc) · 1.08 KB
/
Copy pathindex.js
File metadata and controls
48 lines (38 loc) · 1.08 KB
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
const express = require("express");
const mongoose = require("mongoose");
const dotenv = require("dotenv");
//cors errors
const cors = require("cors");
const { signup, signin } = require("./AuthController");
dotenv.config();
const app = express();
// middleware
app.use(express.json());
//cors calls
app.use(cors({
origin: ["http://127.0.0.1:5500", "http://localhost:5500"],
methods: ["GET", "POST"],
credentials: true
}));
// connect to MongoDB
const connect = async ()=> {
try {
await mongoose.connect(process.env.MONGO_URL,{
useNewUrlParser: true,
useUnifiedTopology: true,
});
console.log("DB ready!")
} catch (error) {
console.error("Falied connection", error.message);
}
}
// direct controller calls without routes
app.post("/signup", signup);
app.post("/signin", signin);
app.get("/", (req, res) => {
res.send(" running!!!");
});
// start server
const PORT = process.env.PORT || 3000;
app.listen(PORT, async () =>{ console.log(`Server running on port ${PORT}`)
await connect();});