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

find-page.js 649 B

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
  1. // This middleware uses the request path to find a page in the preloaded context.pages object
  2. module.exports = async function findPage (req, res, next) {
  3. let page = req.context.pages[req.pagePath]
  4. // if this is a localized request that can't be found, try finding an English variant
  5. if (!page && req.language !== 'en') {
  6. const englishPath = req.pagePath.replace(new RegExp(`^/${req.language}`), '/en')
  7. // NOTE the fallback page will have page.languageCode = 'en'
  8. page = req.context.pages[englishPath]
  9. }
  10. if (page) {
  11. req.context.page = page
  12. req.context.page.version = req.context.currentVersion
  13. }
  14. return next()
  15. }
Tip!

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

Comments

Loading...