-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
47 lines (35 loc) · 1.15 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
43
44
45
46
47
const path = require("path");
var express = require("express");
var logger = require("morgan");
const mongoose = require("mongoose");
const dotenv = require("dotenv");
const passport = require("passport");
var indexRouter = require("./routes/index");
var userRouter = require("./routes/users");
dotenv.config();
var app = express();
// view engine setup
// app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(passport.initialize());
require("./config/passport")(passport);
app.use("/api/", indexRouter);
app.use("/api/user/", userRouter);
// Server static assets if in production
if (process.env.NODE_ENV === "production") {
// Set static folder
app.use(express.static("view/build"));
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "view", "build", "index.html"));
});
}
const port = process.env.PORT || 2000;
mongoose
.connect(process.env.MONGODBURI, { useNewUrlParser: true })
.then(data => {
console.log("DB connected Succesfully");
app.listen(port, () => console.log(`App Running on Port ${port}`));
})
.catch(err => console.log(err));
// module.exports = app;