-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
60 lines (45 loc) · 1.36 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
require('dotenv').config();
const express = require('express')
const session = require('express-session');
const PORT = process.env.PORT;
const app = express()
const bodyParser = require('body-parser')
const mongoose = require('mongoose')
const morgan = require('morgan')
const mongoURI = process.env.MONGO
const authRoutes = require('./routes/auth')
const noteRoutes = require('./routes/notes')
mongoose.connect(mongoURI)
.then((result) => {
console.log('Connected to mongoDB')
app.listen(PORT, ()=> console.log(`Connected to port ${PORT}`))
}).catch((err) => console.log(err))
//middleware
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(morgan('dev'))
app.use(express.static('public'))
// Session Middleware
app.use(session({
secret: 'your_secret_key',
resave: false,
saveUninitialized: true,
cookie: { secure: false } // Set secure: true if using HTTPS
}));
//ejs view engine
app.set('view engine', 'ejs')
app.use(authRoutes)
app.use(noteRoutes)
//routes
app.get('/', (req, res) => {
res.render('index', { title : 'Splash Screen' })
})
app.get('/login', (req, res) => {
res.render('login', {title : 'Login'})
})
app.get('/signup', (req, res) => {
res.render('signup', {title : 'Sign up'})
})
app.use((req, res) => {
res.render('404', {title : 'Page not found'})
})