-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
42 lines (39 loc) · 1.09 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
//ehQcVP7N4COIDvMl
const express = require("express");
const mongoose = require("mongoose");
const { MONGOURI } = require("./config/keys");
const PORT = process.env.PORT || 5000;
mongoose.connect(MONGOURI, {
useUnifiedTopology: true,
useNewUrlParser: true,
useFindAndModify: true,
});
mongoose.connection.on("connected", () => {
console.log("mongoose connected");
});
mongoose.connection.on("error", (err) => {
console.log(err);
});
require("./models/user");
require("./models/expenses");
const authroutes = require("./routes/auth");
const expensesRoutes = require("./routes/expense");
const app = express();
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Headers",
"Origin,X-Requested-With,Content-Type,Accept,Authorization"
);
if (req.method === "OPTIONS") {
res.header("Access-Control-Allow-Methods", "PUT, POST, PATCH, DELETE");
return res.status(200).json({});
}
next();
});
app.use(express.json());
app.use(authroutes);
app.use(expensesRoutes);
app.listen(PORT, () => {
console.log("hello from 3000");
});