3
1

index.ts 1.2 KB

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