-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
163 lines (121 loc) · 2.68 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/**
* @license Apache-2.0
* @copyright 2024 Basavaraja K J
*/
'use strict';
/**
* node modules
*/
const express = require('express');
require('dotenv').config();
const session = require('express-session');
const MongoStore = require('connect-mongo');
/**
* custom modules
*/
const register = require('./src/routes/register_route');
const login = require('./src/routes/login_route');
const { connectDB, disconnectDB } = require('./src/config/mongoose_config');
const home = require('./src/routes/home_route');
const createBlog = require('./src/routes/create_blog_route');
const logout = require('./src/routes/logout_route');
const userAuth = require('./src/middlewares/user_auth_middleware');
const blogDetails = require('./src/routes/blog_detail_route');
const readingList = require('./src/routes/reading_list_route');
const blogUpdate = require('./src/routes/blog-update-route');
const blogDelete = require('./src/routes/blog_delete_route');
const profile = require('./src/routes/profile_route');
const dashboard = require('./src/routes/dashboard_route');
/**
* Initial express
*/
const app = express();
/**
* setting view page
*/
app.set('view engine', 'ejs');
/**
* setting public directory
*/
app.use(express.static(`${__dirname}/public`));
/**
* parse urlencoded body
*/
app.use(express.urlencoded({ extended: true }));
/**
* parse json
*/
app.use(express.json({ limit: '10mb'}));
/**
* instances for session storage
*/
const store = new MongoStore({
mongoUrl: process.env.MANGO_CONNECTION_URI,
collectionName: 'session',
dbName: 'inktale'
})
/**
* initial express session
*/
app.use(session({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false,
store,
cookie: {
maxAge: Number(process.env.SESSION_MAX_AGE)
}
}))
/**
* register page
*/
app.use('/register', register);
/**
* login page
*/
app.use('/login', login);
/**
* sign out
*/
app.use('/logout', logout);
/**
* home page
*/
app.use('/', home);
/**
* blog details page
*/
app.use('/blogs', blogDetails)
/**
* user authorization
*/
app.use('/', userAuth);
/**
* create blog page
*/
app.use('/createblog', createBlog);
/**
* reading list page
*/
app.use('/readinglist', readingList);
/**
* blog update and blog delete
*/
app.use('/blogs', blogUpdate, blogDelete);
/**
* profile page
*/
app.use('/profile', profile);
/**
* dashboard
*/
app.use('/dashboard', dashboard);
/**
* start server
*/
const PORT = process.env.PORT || 3000;
const server = app.listen(3000, async ()=> {
console.log(`server listening on port http://locahost:${PORT}`);
await connectDB(process.env.MANGO_CONNECTION_URI);
});
server.on('close', async () => await disconnectDB());