-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
52 lines (45 loc) · 1.58 KB
/
index.ts
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
import Fastify, {FastifyInstance} from "fastify";
import {mongoConnector} from "./db/mongoConnector";
import {jwtConn} from "./middleware/auth_middleware_jwt";
import {loginRoutes} from "./routes/loginRoutes";
import {workerRoutes} from "./routes/workerRoutes";
import {readersRoutes} from "./routes/readersRoutes";
import {catReadersRoutes} from "./routes/catReaderRoutes";
import {booksRoutes} from "./routes/booksRoutes";
import {catBookRoutes} from "./routes/catBookRoutes";
import {reservRoutes} from "./routes/reservRoutes";
import {borrowRoutes} from "./routes/borrowRoutes";
import {devolutionRoutes} from "./routes/devolutionRoutes";
import {cors} from "./middleware/cors_middleware";
import {config} from "dotenv";
import "fastify-mongodb";
import "fastify-jwt";
config();
const server: FastifyInstance = Fastify({logger: true});
const swagger = require('./config/swagger');
server.register(require('fastify-jwt'), {secret: `${process.env.SECRET}`});
server.register(require('fastify-swagger'), swagger.options);
server.register(cors);
server.register(mongoConnector);
server.register(jwtConn);
server.register(loginRoutes);
server.register(workerRoutes);
server.register(readersRoutes);
server.register(catReadersRoutes);
server.register(booksRoutes);
server.register(catBookRoutes);
server.register(reservRoutes);
server.register(borrowRoutes);
server.register(devolutionRoutes)
const start = async () => {
try {
await server.listen(`${process.env.PORT}`);
} catch (error) {
server.log.error(error);
process.exit(1);
}
};
start().then(v => {
return v;
});
module.exports = server;