-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
79 lines (63 loc) · 1.96 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const express = require('express');
const path = require('path');
const app = express();
const mongoose = require('mongoose');
const passport = require('passport');
const ejs = require('ejs');
const session = require('express-session');
const MongoStore = require('connect-mongo');
const methodOverride = require('method-override');
const flash = require("express-flash");
const logger = require('morgan');
const connectDB = require('./config/database');
const multer = require('multer');
const fs = require('fs');
const mainRoutes = require('./routes/main');
const boardRoutes = require("./routes/dashboard");
const speechRoutes = require("./routes/speech");
const practicaRoutes = require("./routes/practica");
const analysisRoutes = require("./routes/analysis");
// env config
require('dotenv').config( { path: './config/.env' } );
// passport config
require ('./config/passport')(passport);
// connect to database
connectDB();
// Use EJS
app.set('view engine', 'ejs');
// Static folder
app.use( express.static( path.join( __dirname, "public" ) ) );
//Body Parsing
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
//Logging
app.use(logger("dev"));
// Sessions
let store = MongoStore.create({
client: mongoose.connection.getClient()
})
app.use(session({
secret: process.env.SESSION_KEY,
resave: false,
saveUninitialized: false,
store: store
} ) );
app.use(flash());
// Passport middleware
app.use(passport.initialize() );
app.use(passport.session() );
// Set global variable
app.use(function (req, res, next) {
res.locals.user = req.user || null
next()
})
//Use forms for put / delete
app.use(methodOverride("_method"));
// Routes
app.use("/", mainRoutes);
app.use("/dashboard", boardRoutes);
app.use("/speech", speechRoutes);
app.use("/practica", practicaRoutes);
//app.use("/analysis", analysisRoutes);
const PORT = process.env.PORT || 5000;
app.listen(PORT, console.log(`server running in ${process.env.NODE_ENV} mode on port ${PORT}`) );