-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
48 lines (44 loc) · 1.44 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
48
const express=require("express");
const bodyParser=require("body-parser");
const cors=require("cors");
const app=express();
const passport=require("passport");
const mongoose=require("mongoose");
const session=require("express-session");
const MongoStore = require('connect-mongo')(session);
const indexRoutes=require("./routes");
const authRoutes=require("./routes/auth");
const taskRoutes=require("./routes/task");
app.use(cors({
origin:true,
credentials:true
}));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:true}));
app.use(session({
secret:process.env.SECRET,
resave:false,
saveUninitialized:true,
store:new MongoStore({mongooseConnection:mongoose.connection}),
cookie:{expires:24*60*60*1000}
}))
app.use(passport.initialize());
app.use(passport.session());
app.use("/api",indexRoutes);
app.use("/",authRoutes);
app.use("/api",taskRoutes);
if (process.env.NODE_ENV === 'production') {
// Express will serve up production assets
// like our main.js file, or main.css file!
app.use(express.static('frontend'));
// Express will serve up the index.html file
// if it doesn't recognize the route
const path = require('path');
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'frontend', 'index.html'));
});
}
const errorHandlers=require('./handlers/errorHandler');
app.get("*",errorHandlers.notFound);
app.use(errorHandlers.productionErrors);
module.exports=app;