-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
49 lines (42 loc) · 1.25 KB
/
server.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
44
45
46
47
48
49
const dotenv = require("dotenv").config();
const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const passport = require("passport");
const users = require("./routes/api/users");
const farms = require("./routes/api/farms");
const cors = require("cors");
const app = express();
const port = process.env.PORT || 5000;
app.use(
cors({
allowedHeaders: ["sessionId", "Content-Type"],
exposedHeaders: ["sessionId"],
origin: "*",
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
preflightContinue: false,
})
);
app.use(
bodyParser.urlencoded({
extended: false,
})
);
app.use(bodyParser.json({limit: '50mb', extended: true}));
mongoose.connect(process.env.DATABASE, {
useNewUrlParser: true,
});
mongoose.set("useCreateIndex", true);
mongoose.Promise = global.Promise;
mongoose.connection
.on("connected", () => {
console.log(`Mongoose connection open on ${process.env.DATABASE}`);
})
.on("error", err => {
console.log(`Connection error: ${err.message}`);
});
app.use(passport.initialize());
require("./config/passport")(passport);
app.use("/api/users", users);
app.use("/api/farms", farms);
app.listen(port, () => console.log(`Server up and running on port ${port} !`));