-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
32 lines (27 loc) · 1.02 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
const express = require('express');
const mongoose = require('mongoose');
const authRoutes = require('./routes/authRoutes');
const cookieParser = require('cookie-parser');
const { requireAuth,checkOwner, checkUser } = require('./middleware/authMiddleware');
const eventRoutes = require('./routes/EventRoutes')
const applyRoutes = require('./routes/applyRoutes')
const app = express();
// middleware
app.use(express.static('public'));
app.use(express.json());
app.use(cookieParser());
// view engine
app.set('view engine', 'ejs');
// database connection
const dbURI = 'mongodb+srv://snehal:[email protected]/test?retryWrites=true&w=majority&appName=CC';
mongoose.connect(dbURI)
.then((result) => app.listen(3000))
.catch((err) => console.log(err));
app.use(express.urlencoded({extended:true}));
// routes
app.use('/events',eventRoutes);
app.use(applyRoutes);
app.get('*', checkUser);
app.get('/', (req, res) => res.render('home'));
app.get('/geneticx', requireAuth, (req, res) => res.render('geneticx'));
app.use(authRoutes);