]>
Commit | Line | Data |
---|---|---|
1 | import * as cors from 'cors' | |
2 | import * as express from 'express' | |
3 | import * as RateLimit from 'express-rate-limit' | |
4 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | |
5 | import { badRequest } from '../../helpers/express-utils' | |
6 | import { CONFIG } from '../../initializers/config' | |
7 | import { abuseRouter } from './abuse' | |
8 | import { accountsRouter } from './accounts' | |
9 | import { bulkRouter } from './bulk' | |
10 | import { configRouter } from './config' | |
11 | import { jobsRouter } from './jobs' | |
12 | import { oauthClientsRouter } from './oauth-clients' | |
13 | import { overviewsRouter } from './overviews' | |
14 | import { pluginRouter } from './plugins' | |
15 | import { searchRouter } from './search' | |
16 | import { serverRouter } from './server' | |
17 | import { usersRouter } from './users' | |
18 | import { videoChannelRouter } from './video-channel' | |
19 | import { videoPlaylistRouter } from './video-playlist' | |
20 | import { videosRouter } from './videos' | |
21 | ||
22 | const apiRouter = express.Router() | |
23 | ||
24 | apiRouter.use(cors({ | |
25 | origin: '*', | |
26 | exposedHeaders: 'Retry-After', | |
27 | credentials: true | |
28 | })) | |
29 | ||
30 | const apiRateLimiter = RateLimit({ | |
31 | windowMs: CONFIG.RATES_LIMIT.API.WINDOW_MS, | |
32 | max: CONFIG.RATES_LIMIT.API.MAX | |
33 | }) | |
34 | apiRouter.use(apiRateLimiter) | |
35 | ||
36 | apiRouter.use('/server', serverRouter) | |
37 | apiRouter.use('/abuses', abuseRouter) | |
38 | apiRouter.use('/bulk', bulkRouter) | |
39 | apiRouter.use('/oauth-clients', oauthClientsRouter) | |
40 | apiRouter.use('/config', configRouter) | |
41 | apiRouter.use('/users', usersRouter) | |
42 | apiRouter.use('/accounts', accountsRouter) | |
43 | apiRouter.use('/video-channels', videoChannelRouter) | |
44 | apiRouter.use('/video-playlists', videoPlaylistRouter) | |
45 | apiRouter.use('/videos', videosRouter) | |
46 | apiRouter.use('/jobs', jobsRouter) | |
47 | apiRouter.use('/search', searchRouter) | |
48 | apiRouter.use('/overviews', overviewsRouter) | |
49 | apiRouter.use('/plugins', pluginRouter) | |
50 | apiRouter.use('/ping', pong) | |
51 | apiRouter.use('/*', badRequest) | |
52 | ||
53 | // --------------------------------------------------------------------------- | |
54 | ||
55 | export { apiRouter } | |
56 | ||
57 | // --------------------------------------------------------------------------- | |
58 | ||
59 | function pong (req: express.Request, res: express.Response) { | |
60 | return res.send('pong').status(HttpStatusCode.OK_200).end() | |
61 | } |