Skip to content

fix nginx conf #896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 24, 2021
Merged

fix nginx conf #896

merged 3 commits into from
Jun 24, 2021

Conversation

Rainshaw
Copy link
Contributor

@Rainshaw Rainshaw commented Jun 2, 2021

Description

using nginx conf of last version, IN app/src/infrastructure/Translations.js the setLangBasedOnDomainMiddleware would get the req.headers.host as 127.0.0.1:3000 not the domain. and this leads to the failing multi-languages support.

To Reproduce, make a clean install with multi-languages settings, add the following log commant to the file app/src/infrastructure/Translations.js, and restart the container:

const logger = require('logger-sharelatex')
function setLangBasedOnDomainMiddleware(req, res, next) {
  // Determine language from subdomain
  const lang = availableHosts.get(req.headers.host)
  if (lang) {
    req.i18n.changeLanguage(lang)
  }
// add this line !!!!!!!
  logger.log(`host: ${req.headers.host}, lang: ${lang}`)

  // expose the language code to pug
  res.locals.currentLngCode = req.language

  // If the set language is different from the language detection (based on
  // the Accept-Language header), then set flag which will show a banner
  // offering to switch to the appropriate library
  const detectedLanguageCode = headerLangDetector.detect(req, res)
  if (req.language !== detectedLanguageCode) {
    res.locals.suggestedLanguageSubdomainConfig = subdomainConfigs.get(
      detectedLanguageCode
    )
  }

  // Decorate req.i18n with translate function alias for backwards
  // compatibility usage in requests
  req.i18n.translate = req.i18n.t
  next()
}

and in the log of web, we can see this:

{"name":"web","hostname":"3d37c48f1b4a","pid":166,"level":30,"msg":"host: 127.0.0.1:3000, lang: undefined","time":"2021-06-02T13:33:20.494Z","v":0}

with this fix, the log would be:

{"name":"web","hostname":"0f11a0bb43e8","pid":157,"level":30,"msg":"host: www.domain.com, lang: en","time":"2021-06-02T13:39:10.981Z","v":0}

Contributor Agreement

@Rainshaw
Copy link
Contributor Author

@mserranom Any thoughts on this pull request? It would be really nice to get this upstream.

@mserranom
Copy link
Contributor

Many thanks @RainshawGao , I see the issue with Host header regarding i18n. Did you spot any problem requiring X-Real-IP and REMOTE-HOST to be included?

Cc @ShaneKilkelly

@Rainshaw
Copy link
Contributor Author

oh, not really, maybe this project do not use these values. I add them because they are common in a reverse proxy setting.

if you'd like to del them, i will do it and push. 😊

Copy link
Contributor

@JuneKelly JuneKelly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 🎉

@JuneKelly JuneKelly assigned mserranom and unassigned JuneKelly Jun 16, 2021
@jdleesmiller
Copy link
Member

Thanks for the PR. I would lean toward including only the headers we know are required, i.e. just Host, as per #896 (comment). So, @RainshawGao , yes, I think if you remove those that would be preferred.

@Rainshaw
Copy link
Contributor Author

Ok, I have done that, @jdleesmiller @mserranom @ShaneKilkelly 😊

@Rainshaw Rainshaw requested a review from JuneKelly June 19, 2021 12:04
@mserranom mserranom merged commit c4ead8f into overleaf:master Jun 24, 2021
@Rainshaw Rainshaw deleted the fix-nginx-host branch July 1, 2021 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants