ニジカ投稿局 https://tv.nizika.tv
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.ts 2.8 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { HttpStatusCode } from '@peertube/peertube-models'
  2. import { logger } from '@server/helpers/logger.js'
  3. import cors from 'cors'
  4. import express from 'express'
  5. import { abuseRouter } from './abuse.js'
  6. import { accountsRouter } from './accounts.js'
  7. import { automaticTagRouter } from './automatic-tags.js'
  8. import { blocklistRouter } from './blocklist.js'
  9. import { bulkRouter } from './bulk.js'
  10. import { configRouter } from './config.js'
  11. import { customPageRouter } from './custom-page.js'
  12. import { jobsRouter } from './jobs.js'
  13. import { metricsRouter } from './metrics.js'
  14. import { oauthClientsRouter } from './oauth-clients.js'
  15. import { overviewsRouter } from './overviews.js'
  16. import { pluginRouter } from './plugins.js'
  17. import { runnersRouter } from './runners/index.js'
  18. import { searchRouter } from './search/index.js'
  19. import { serverRouter } from './server/index.js'
  20. import { usersRouter } from './users/index.js'
  21. import { videoChannelSyncRouter } from './video-channel-sync.js'
  22. import { videoChannelRouter } from './video-channel.js'
  23. import { videoPlaylistRouter } from './video-playlist.js'
  24. import { videosRouter } from './videos/index.js'
  25. import { watchedWordsRouter } from './watched-words.js'
  26. const apiRouter = express.Router()
  27. apiRouter.use(cors({
  28. origin: '*',
  29. exposedHeaders: 'Retry-After',
  30. credentials: true
  31. }))
  32. apiRouter.use('/server', serverRouter)
  33. apiRouter.use('/abuses', abuseRouter)
  34. apiRouter.use('/bulk', bulkRouter)
  35. apiRouter.use('/oauth-clients', oauthClientsRouter)
  36. apiRouter.use('/config', configRouter)
  37. apiRouter.use('/users', usersRouter)
  38. apiRouter.use('/accounts', accountsRouter)
  39. apiRouter.use('/video-channels', videoChannelRouter)
  40. apiRouter.use('/video-channel-syncs', videoChannelSyncRouter)
  41. apiRouter.use('/video-playlists', videoPlaylistRouter)
  42. apiRouter.use('/videos', videosRouter)
  43. apiRouter.use('/jobs', jobsRouter)
  44. apiRouter.use('/metrics', metricsRouter)
  45. apiRouter.use('/search', searchRouter)
  46. apiRouter.use('/overviews', overviewsRouter)
  47. apiRouter.use('/plugins', pluginRouter)
  48. apiRouter.use('/custom-pages', customPageRouter)
  49. apiRouter.use('/blocklist', blocklistRouter)
  50. apiRouter.use('/runners', runnersRouter)
  51. apiRouter.use('/watched-words', watchedWordsRouter)
  52. apiRouter.use('/automatic-tags', automaticTagRouter)
  53. apiRouter.use('/ping', pong)
  54. apiRouter.use('/*', badRequest)
  55. // ---------------------------------------------------------------------------
  56. export { apiRouter }
  57. // ---------------------------------------------------------------------------
  58. function pong (req: express.Request, res: express.Response) {
  59. return res.send('pong').status(HttpStatusCode.OK_200).end()
  60. }
  61. function badRequest (req: express.Request, res: express.Response) {
  62. logger.debug(`API express handler not found: bad PeerTube request for ${req.method} - ${req.originalUrl}`)
  63. return res.type('json')
  64. .status(HttpStatusCode.BAD_REQUEST_400)
  65. .end()
  66. }