-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
41 lines (33 loc) · 1.08 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
const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const morgan = require("morgan");
const { join } = require("path");
const routes = require("./routes");
const app = express();
// Loading dotenv file
require("dotenv").config();
// Logger middleware
morgan(":method :url :status :res[content-length] - :response-time ms");
// Mongoose connection string
mongoose.connect("mongodb://127.0.0.1:27017/passport-jwt");
// Mongoose error handler
mongoose.connection.on("error", (error) => console.log(error));
// Mongoose promise configuration
mongoose.Promise = global.Promise;
// Loading auth middleware
require("./auth/auth");
// Loading bodyparser middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
console.log(__dirname);
// Serves up react app
app.use(express.static(join(__dirname, "/client/build")));
// Routes configuration
app.use(routes);
//Handle errors
app.use(function (err, req, res, next) {
res.status(err.status || 500);
res.json({ error: err });
});
module.exports = app;