1
0

index.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. const router = require('express').Router()
  2. import intro from '../intro'
  3. router.use('/v1/blocks', require('./blocks'))
  4. router.use('/v1/events', require('./events'))
  5. router.use('/v1/eras', require('./eras'))
  6. router.use('/v1/accounts', require('./accounts'))
  7. router.use('/v1/councils', require('./councils'))
  8. router.use('/v1/members', require('./members'))
  9. router.use('/v1/proposals', require('./proposals'))
  10. router.use('/v1/channels', require('./channels'))
  11. router.use('/v1/categories', require('./categories'))
  12. router.use('/v1/threads', require('./threads'))
  13. router.use('/v1/posts', require('./posts'))
  14. router.get('/v1', (req: any, res: any, next: any) => {
  15. try {
  16. res.send(`<pre>${intro}</pre>`)
  17. } catch (err) {
  18. console.log(err)
  19. next()
  20. }
  21. })
  22. router.get('/', (req: any, res: any, next: any) => {
  23. try {
  24. const versions = ['v1']
  25. res.send(`Available versions: <ul><li><a href='/api/v1'>/v1</a></li></ul>`)
  26. } catch (err) {
  27. console.log(err)
  28. next()
  29. }
  30. })
  31. router.use((req: any, res: any, next: any) => {
  32. const error = new Error(`Not Found: /api${req.url}`)
  33. //console.log(req)
  34. //error.status = 404
  35. next(error)
  36. })
  37. module.exports = router