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

archived-enterprise-versions-assets.js 1.4 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
36
37
  1. const path = require('path')
  2. const patterns = require('../lib/patterns')
  3. const isArchivedVersion = require('../lib/is-archived-version')
  4. const got = require('got')
  5. const ONE_DAY = 24 * 60 * 60 // 1 day in seconds
  6. // This module handles requests for the CSS and JS assets for
  7. // deprecated GitHub Enterprise versions by routing them to static content in
  8. // help-docs-archived-enterprise-versions
  9. //
  10. // See also ./archived-enterprise-versions.js for non-CSS/JS paths
  11. module.exports = async function archivedEnterpriseVersionsAssets (req, res, next) {
  12. const { isArchived, requestedVersion } = isArchivedVersion(req)
  13. if (!isArchived) return next()
  14. // Only match asset paths
  15. if (!patterns.assetPaths.test(req.path)) return next()
  16. const assetPath = req.path.replace(`/enterprise/${requestedVersion}`, '')
  17. const proxyPath = path.join('/', requestedVersion, assetPath)
  18. try {
  19. const r = await got(`https://github.github.com/help-docs-archived-enterprise-versions${proxyPath}`)
  20. res.set('accept-ranges', 'bytes')
  21. res.set('content-type', r.headers['content-type'])
  22. res.set('content-length', r.headers['content-length'])
  23. res.set('x-is-archived', 'true')
  24. res.set('x-robots-tag', 'noindex')
  25. // Allow the browser and Fastly to cache these
  26. res.set('cache-control', `public, max-age=${ONE_DAY}`)
  27. return res.send(r.body)
  28. } catch (err) {
  29. return next()
  30. }
  31. }
Tip!

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

Comments

Loading...