This repository was archived by the owner on Jul 2, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
98 lines (81 loc) · 2.42 KB
/
Copy pathindex.js
File metadata and controls
98 lines (81 loc) · 2.42 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import express from 'express';
import IndexV1 from './src/v1/index.js';
import IndexV2 from './src/v2/index.js';
import rateLimit from 'express-rate-limit';
import helmet from 'helmet';
import swaggerJsDoc from 'swagger-jsdoc';
import swaggerUi from 'swagger-ui-express';
import favicon from 'serve-favicon';
import path from 'path';
import cors from 'cors';
import { readFileSync } from 'fs';
const {PORT} = JSON.parse(readFileSync("./config.json"));
const limiter = rateLimit({
windowMs: 15 * 60 * 1000,
max: 50,
message: 'You have reached the rate limit of 20 requests per 15 minutes.',
headers: true,
});
const app = express();
app.set('trust proxy', 1);
app.use(
cors({
exposedHeaders: ['Authorisation'],
}),
);
app.use(helmet());
app.use(limiter);
app.use(express.json());
const thedamnPath = path.join('.', 'src', 'v2', 'image', 'gifs');
app.use('/gifs', express.static(path.join(thedamnPath)));
app.use(favicon(path.join('.', 'src', 'assets', 'images', 'favicon.ico')));
const options = {
customCss: '.swagger-ui .topbar { display: none }',
};
const swaggerOptions = swaggerJsDoc({
swaggerDefinition: {
info: {
title: 'Obama API',
description: 'Obama Bot API',
},
servers: 'https://api.obamabot.me',
host: 'api.obamabot.me',
basePath: '/v1',
externalDocs: {
description: 'Find out more about Obama Bot',
url: 'https://obamabot.me',
},
securityDefinitions: null,
},
explorer: true,
apis: ['./src/v1/Images/*.js', './src/v1/text/*.js', './src/v1/text/osu/*.js'],
});
const swaggerOptionsV2 = swaggerJsDoc({
swaggerDefinition: {
info: {
title: 'Obama API',
description: 'Obama API general porpuse api for alot of projects.',
},
servers: 'https://api.obamabot.me',
host: 'api.obamabot.me',
basePath: '/v2',
externalDocs: {
description: 'Find out more about Obama Bot',
url: 'https://obamabot.me',
},
securityDefinitions: null,
},
explorer: true,
apis: ['./src/v2/image/*.js', './src/v2/text/*/*.js'],
});
// Version 1 No longer updated
app.use('/v1', IndexV1);
// Version 2 Currently been updated
app.use('/v2', IndexV2);
// Documents
app.use('/v1/docs', swaggerUi.serveFiles(swaggerOptions), swaggerUi.setup(swaggerOptions, options));
app.use('/v2/docs', swaggerUi.serveFiles(swaggerOptionsV2), swaggerUi.setup(swaggerOptionsV2, options));
app.get('/', (req, res) => {
res.redirect('/v2/docs');
});
app.listen(PORT, () => console.log('server Running on: https://api.obamabot.me'));