index.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import * as express from 'express'
  2. import { configRouter } from './config'
  3. import { jobsRouter } from './jobs'
  4. import { oauthClientsRouter } from './oauth-clients'
  5. import { serverRouter } from './server'
  6. import { usersRouter } from './users'
  7. import { accountsRouter } from './accounts'
  8. import { videosRouter } from './videos'
  9. import { badRequest } from '../../helpers/express-utils'
  10. import { videoChannelRouter } from './video-channel'
  11. import * as cors from 'cors'
  12. import { searchRouter } from './search'
  13. import { overviewsRouter } from './overviews'
  14. import { videoPlaylistRouter } from './video-playlist'
  15. const apiRouter = express.Router()
  16. apiRouter.use(cors({
  17. origin: '*',
  18. exposedHeaders: 'Retry-After',
  19. credentials: true
  20. }))
  21. apiRouter.use('/server', serverRouter)
  22. apiRouter.use('/oauth-clients', oauthClientsRouter)
  23. apiRouter.use('/config', configRouter)
  24. apiRouter.use('/users', usersRouter)
  25. apiRouter.use('/accounts', accountsRouter)
  26. apiRouter.use('/video-channels', videoChannelRouter)
  27. apiRouter.use('/video-playlists', videoPlaylistRouter)
  28. apiRouter.use('/videos', videosRouter)
  29. apiRouter.use('/jobs', jobsRouter)
  30. apiRouter.use('/search', searchRouter)
  31. apiRouter.use('/overviews', overviewsRouter)
  32. apiRouter.use('/ping', pong)
  33. apiRouter.use('/*', badRequest)
  34. // ---------------------------------------------------------------------------
  35. export { apiRouter }
  36. // ---------------------------------------------------------------------------
  37. function pong (req: express.Request, res: express.Response) {
  38. return res.send('pong').status(200).end()
  39. }