Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

rest.js 1.2 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  1. const path = require('path')
  2. const rest = require('../../lib/rest')
  3. const removeFPTFromPath = require('../../lib/remove-fpt-from-path')
  4. module.exports = function restContext (req, res, next) {
  5. req.context.rest = rest
  6. // link to include in `Works with GitHub Apps` notes
  7. // e.g. /ja/rest/reference/apps or /en/enterprise/2.20/user/rest/reference/apps
  8. req.context.restGitHubAppsLink = removeFPTFromPath(path.join(
  9. '/',
  10. req.context.currentLanguage,
  11. req.context.currentVersion,
  12. '/developers/apps'
  13. ))
  14. // ignore requests to non-REST reference paths
  15. if (!req.pagePath.includes('rest/reference')) return next()
  16. // e.g. the `activity` from `/en/rest/reference/activity#events`
  17. const category = req.pagePath
  18. .split('rest/reference')[1]
  19. .replace(/^\//, '') // remove leading slash
  20. .split('/')[0]
  21. // ignore empty strings or bare `/`
  22. if (!category || category.length < 2) return next()
  23. const operationsForCurrentProduct = req.context.rest.operations[req.context.currentVersion] || []
  24. // find all operations with a category matching the current path
  25. req.context.currentRestOperations = operationsForCurrentProduct.filter(operation => operation.category === category)
  26. return next()
  27. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...