-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (51 loc) · 1.82 KB
/
index.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
import express from 'express';
import cors from 'cors';
import path from 'path';
import dotenv from 'dotenv';
import { authRouter, usersRouter, animalsRouter, tagsRouter, rolesRouter, photosRouter, adoptRouter } from './app/routers/index.js';
import expressJSDocSwagger from 'express-jsdoc-swagger';
import * as url from 'url';
import errorService from "./app/service/errorHandling.js";
const app = express();
dotenv.config();
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
app.use(express.static(path.join(__dirname, './public/')));
app.use('/images', express.static(path.join(__dirname, 'public/images')));
app.use(cors('https://adopte-un-humain.netlify.app/'));
/****************************/
/**** Swagger generator ****/
/****************************/
// Définition des options de configuration de Swagger
const options = {
info: {
version: '1.0.0',
title: 'J\'Adopte un humain',
description: 'My API with Swagger documentation',
license: {
name: 'MIT',
},
},
security: {
bearerAuth: {
type: 'http',
scheme: 'bearer'
}
},
baseDir: __dirname,
filesPattern: './**/*.js'
};
// Appel de la fonction expressJSDocSwagger() pour lui passer les options de configuration
expressJSDocSwagger(app)(options);
/* Autorisation de recevoir des données de type JSON */
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
/* Mise en place du router */
app.use("/api",authRouter, usersRouter, animalsRouter, tagsRouter, rolesRouter, photosRouter, adoptRouter);
/* gestion globale des erreurs */
app.use(errorService.manage);
/* Lancement du serveur */
const PORT = process.env.PORT ?? 3000;
app.listen(PORT, () => {
console.log(`Server ready : http://${process.env.APP_URL}:${PORT}`);
});
export default app;