Skip to content

Commit b9a0e00

Browse files
crypt-ex
1 parent 40d54e5 commit b9a0e00

File tree

3,993 files changed

+490438
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,993 files changed

+490438
-0
lines changed

.DS_Store

8 KB
Binary file not shown.

Procfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: node app.js

app.js

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
var express = require('express');
2+
var mongoose = require('mongoose');
3+
var bodyParser = require('body-parser');
4+
var passport = require('passport');
5+
var session = require('express-session');
6+
var MongoStore = require('connect-mongo')(session);
7+
var LocalStrategy = require('passport-local').Strategy;
8+
9+
var app = express();
10+
11+
//Make new databse
12+
mongoose.connect("mongodb://MINET:[email protected]:31583/minetx");
13+
var db = mongoose.connection;
14+
//If Mongo Error
15+
db.on('error', console.error.bind(console, 'connection error'));
16+
17+
//Setting up sessions+cookies
18+
app.use(session({
19+
secret: 'JagdishKumar',
20+
resave: false,
21+
saveUninitialized: false,
22+
store: new MongoStore({
23+
mongooseConnection: db
24+
})
25+
}));
26+
app.use(passport.initialize());
27+
app.use(passport.session());
28+
29+
var User = require('./models/user');
30+
passport.use(new LocalStrategy(User.authenticate()));
31+
passport.serializeUser(User.serializeUser());
32+
passport.deserializeUser(User.deserializeUser());
33+
34+
// var Question = require('./models/question');
35+
36+
app.use((req, res, next) => {
37+
res.locals.currentUser = req.user;
38+
next();
39+
});
40+
41+
//Setting up body-parser
42+
app.use(bodyParser.json());
43+
app.use(bodyParser.urlencoded({ extended: false }));
44+
45+
//Setting public directory
46+
app.use(express.static(__dirname + '/public'));
47+
48+
//Setting view engine
49+
app.set('view engine', 'pug');
50+
app.set('views', __dirname + '/views');
51+
52+
//Setting routes
53+
var routes = require('./routes/index');
54+
app.use('/', routes);
55+
56+
//Setting routes
57+
var admin = require('./routes/admin');
58+
app.use('/admin', admin);
59+
60+
//404
61+
app.use((res, req, next) => {
62+
var err = new Error('File not found!');
63+
err.status = 404;
64+
next(err);
65+
});
66+
67+
//Error Handler
68+
app.use((err, req, res, next) => {
69+
res.status(err.status || 500);
70+
res.render('error', {
71+
title: 'Error',
72+
message: err.message,
73+
error: {}
74+
});
75+
});
76+
77+
//Listening
78+
app.listen(process.env.PORT || 7000);

0 commit comments

Comments
 (0)