-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
62 lines (57 loc) · 1.63 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 router from './api/v1/routes/index';
import swaggerUi from 'swagger-ui-express';
import swaggerJsDoc from 'swagger-jsdoc';
import cors from 'cors';
import config from 'config';
import { login, verifyAuth, loginLimit } from './login/index';
// init configs
const port = config.get('PORT') || 3001;
// init swagger configs
const swaggerOptions = {
swaggerDefinition: {
info: {
title: 'Currency Converter API',
version: '1.0.0',
description: 'REST API used by the Currency Converter tool',
contact: {
name: 'Lochana Ranaweera',
},
servers: ['http://localhost:3001'],
},
},
apis: ['index.js', './api/v1/routes/index.js'],
};
const swaggerDocs = swaggerJsDoc(swaggerOptions);
const app = express();
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocs));
app.use(cors());
app.use('/login', loginLimit);
/**
* @swagger
* /login:
* get:
* description: Used to obtain JWT required to login
* responses:
* '200':
* description: Success
* schema:
* type: string
* example: "eyJhbGciOiJIUzI1NiJ9.bG9nZ2VkX2l69MJAI-41pu1VffYFl9PX4raikMAo20J3Ex2k"
* '429':
* description: Error response
* schema:
* type: string
* example: "Too many requests, please try again later."
*/
app.use('/login', login);
app.use(verifyAuth);
app.use('/api/v1/', router);
app.use((err, _req, res, next) => {
if (err.status === 401) {
res.status(401).json(err);
} else {
next(err);
}
});
app.listen(port, () => console.log(`Currency Converter BFF listening on port ${port}!`));