-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
113 lines (88 loc) · 3.49 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
const createError = require('http-errors');
const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
//Extras
const dotenv = require('dotenv');
dotenv.config();
const indexRouter = require('./routes/index');
const authenticationRouter = require('./routes/authentication');
const categoriesRouter = require('./routes/categories');
const contentsCategoriesRouter = require('./routes/contentsCategories');
const contentsTypesRouter = require('./routes/contentsTypes');
const contentsDetailsRouter = require('./routes/contentsDetails');
const contentsRouter = require('./routes/contents');
const seriesRouter = require('./routes/series');
const usersListsRouter = require('./routes/usersLists');
const usersRoomsRouter = require('./routes/usersRooms');
const usersScoresRouter = require('./routes/usersScores');
const usersCommentsRouter = require('./routes/usersComments');
const usersActivitiesRouter = require('./routes/usersActivities');
const usersRouter = require('./routes/users');
const roomsActivitiesRouter = require('./routes/roomsActivities');
const roomsRouter = require('./routes/rooms');
const friendsRouter = require('./routes/friends');
const activitiesRouter = require('./routes/activities');
const servicesRouter = require('./routes/services');
const app = express();
//DB
const db = require('./helpers/db');
// db.connect();
const controlDb = async () => {
try {
await db.authenticate();
console.log('Connection has been established successfully.');
} catch (error) {
console.error('Unable to connect to the database:', error);
}
}
controlDb();
// Config
const config = require('./config');
app.set('api_secret_key', config.api_secret_key); //Global kullanıma izin verme.
// Middleware
const verifyToken = require('./middleware/verify-token');
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRouter);
app.use('/api', verifyToken);
app.use('/authentication', authenticationRouter);
app.use('/api/categories', categoriesRouter);
app.use('/api/contents/categories', contentsCategoriesRouter);
app.use('/api/contents/types', contentsTypesRouter);
app.use('/api/contents/details', contentsDetailsRouter);
app.use('/api/contents', contentsRouter);
app.use('/api/series', seriesRouter);
app.use('/api/users/lists', usersListsRouter);
app.use('/api/users/rooms', usersRoomsRouter);
app.use('/api/users/scores', usersScoresRouter);
app.use('/api/users/comments', usersCommentsRouter);
app.use('/api/users/activities', usersActivitiesRouter);
app.use('/api/users', usersRouter);
app.use('/api/rooms/activities', roomsActivitiesRouter);
app.use('/api/rooms', roomsRouter);
app.use('/api/friends', friendsRouter);
app.use('/api/activities', activitiesRouter);
app.use('/api/services', servicesRouter);
// catch 404 and forward to error handler
app.use((req, res, next) => {
res.status(404).json({ 'notification': 'Route not found.' })
next(createError(404));
});
// error handler
app.use((err, req, res, next) => {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
module.exports = app;