-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (30 loc) · 1.88 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
import express, { Router } from 'express';
import config from './config/config.js';
import handlersSecurity from './handlers/handlersSecurity.js';
import handlersTrainers from './handlers/handlersTrainers.js';
import handlersPokemon from './handlers/handlersPokemon.js';
import handlersExchange from './handlers/handlersExchange.js';
import swaggerUi from 'swagger-ui-express';
import swaggerDocument from './swagger.json' assert { type : 'json' };
const OauthRouter = Router();
const app = express();
app.use(express.json());
app.use(OauthRouter);
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument))
OauthRouter.post('/oauth/token', [handlersSecurity.getToken]);
OauthRouter.get('/authorize', [handlersSecurity.authorize]);
app.get('/trainer/:id', [handlersSecurity.checkAuthorization, handlersTrainers.getTrainer]);
app.post('/register', [handlersTrainers.createTrainer]);
app.patch('/trainer/:id', [handlersSecurity.checkAuthorization, handlersSecurity.isUserAuthorized, handlersTrainers.modifyTrainer]);
app.delete('/trainer/:id', [handlersSecurity.checkAuthorization, handlersSecurity.isUserAuthorized, handlersTrainers.deleteTrainer]);
app.get('/pokemon', [handlersSecurity.checkAuthorization, handlersPokemon.getPokemon]);
app.patch('/pokemon/:id', [handlersSecurity.checkAuthorization, handlersSecurity.isUserAuthorizedPokemon, handlersPokemon.modifyPokemon]);
app.delete('/pokemon/:id', [handlersSecurity.checkAuthorization, handlersSecurity.isUserAuthorizedPokemon, handlersPokemon.deletePokemon]);
app.post('/exchange/:id', [handlersSecurity.checkAuthorization, handlersExchange.exchangePurpose]);
app.patch('/exchange/:id', [handlersSecurity.checkAuthorization, handlersExchange.exchangeResponse]);
app.use((req, res) => {
res.status(404).send('URL not found');
});
app.listen(config.NODE_APP_PORT, () => {
console.log(`The server is up on port ${config.NODE_APP_PORT}`);
});