-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
60 lines (45 loc) · 1.41 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
const express = require('express');
const cors = require('cors');
const sequelize = require('./sequelize');
//import routes
const loginRoutes = require('./routes/login');
const registerRoutes = require('./routes/register');
const userRoutes = require('./routes/user');
const fileRoutes = require('./routes/file');
const notificationRoutes = require('./routes/notification');
const logRoutes = require('./routes/log');
const app = express();
// body-parser
app.use(express.json({limit: '50mb'}));
app.use(express.urlencoded({ extended: true, limit: '50mb' }));
// cors policy
app.use(cors());
// connexion à la BDD
async function assertDatabaseConnectionOk() {
console.log(`Checking database connection...`);
try {
await sequelize.authenticate();
console.log('Database connection OK!');
} catch (error) {
console.log('Unable to connect to the database:');
console.log(error.message);
process.exit(1);
}
}
//init authentication to database
async function init() {
await assertDatabaseConnectionOk();
}
init();
//------------- Différentes routes -------------//
// authentication
app.use('/api/login', loginRoutes);
app.use('/api/register', registerRoutes);
// main
app.use('/api/user', userRoutes);
app.use('/api/file', fileRoutes);
// secondary
app.use('/api/notification', notificationRoutes);
app.use('/api/log', logRoutes);
// app.use('/api/userNotification', userNotificationRoutes);
module.exports = app;