-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
56 lines (50 loc) · 1.82 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
const express = require('express'),
mongoose = require('mongoose'),
bodyParser = require('body-parser'),
methodOverride = require('method-override'),
path = require('path'),
passport = require('passport'),
LocalStrategy = require('passport-local'),
Record = require('./models/record'),
User = require('./models/user'),
pdfMake = require('./pdfmake/pdfmake'),
vfsFonts = require('./pdfmake/vfs_fonts'),
recordsRoutes = require('./routes/records'),
reportsRoutes = require('./routes/reports'),
printRoutes = require('./routes/print'),
indexRoutes = require('./routes/index'),
app = express();
// APP CONFIG
app.use(express.static('public'));
app.set("view engine","ejs");
app.use(bodyParser.urlencoded({extended: true}));
app.use(methodOverride("_meth"));
// MONGO SETUP
mongoose.set('useCreateIndex', true);
mongoose.set('useNewUrlParser', true);
mongoose.set('useFindAndModify', false);
mongoose.connect(process.env.DATABASEURL || "mongodb://localhost:27017/GFS",{useNewUrlParser: true, useUnifiedTopology: true});
// PDF MAKE SETUP
pdfMake.vfs = vfsFonts.pdfMake.vfs;
app.use(express.static(path.join(__dirname, 'public')));
// USER AUTHENTICATION SETUP
app.use(require('express-session')({
secret: "Try Me Bitch",
resave: false,
saveUninitialized: false
}));
app.use(passport.initialize());
app.use(passport.session());
passport.use(new LocalStrategy(User.authenticate()));
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());
// USING ROUTES
app.use(recordsRoutes);
app.use(reportsRoutes);
// app.use(printRoutes);
app.use(indexRoutes);
//LISTENS FOR CALLS TO THE WEBSITE
app.listen(process.env.PORT || 3000,process.env.IP,() => {
console.log(process.env.PORT || 3000);
console.log("!!SERVER STARTED!!");
});