Skip to content
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

RuntimeConfigs in serverless mode #10395

Closed
gurkerl83 opened this issue Feb 3, 2020 · 6 comments · Fixed by #10402
Closed

RuntimeConfigs in serverless mode #10395

gurkerl83 opened this issue Feb 3, 2020 · 6 comments · Fixed by #10402

Comments

@gurkerl83
Copy link
Contributor

gurkerl83 commented Feb 3, 2020

This issues continues findings from #10385

The following commits made runtimeConfigs in _document, _app etc available c01534c

My tests indicate that both variables (publicRuntimeConfig and serverRuntimeConfig a) are available in those components, but only in a production build.

In development mode runtimeConfigs are still undefined.
Also RuntimeConfigs are undefined in the document middleware.

@ijjk
Copy link
Member

ijjk commented Feb 3, 2020

Hi, I opened a PR addressing the runtime configs in dev mode although we don't recommend using document middleware as it's not something we plan to make stable/keep at this time and is why it's under an experimental flag

@gurkerl83
Copy link
Contributor Author

gurkerl83 commented Feb 3, 2020

Hi thanks for the changes regarding the development mode. The use case to be supported by the Document Middleware is that a translation capability can be introduced into an application. To do this, a variable must be set that identifies the root directory. If the file system is addressed in an application rolled out with Now, the root directory cannot be resolved. So the idea is to read the root directory in next.config.js and store it for the application via runtimeConfig.

A ticket that deals with this problem is among others

#8251 (comment)

See here

Document middleware in _document.js

https://github.com/project-millipede/millipede-docs/blob/ab8280a90a148b506d4dd3d4c7b421429605bc87/pages/_document.tsx#L24

Configuration of next-i18next

https://github.com/project-millipede/millipede-docs/blob/ab8280a90a148b506d4dd3d4c7b421429605bc87/i18n.ts#L4

Unfortunately not working

projectRoot: process.env.PROJECT_ROOT,

idea use
projectRoot: serverRuntimeConfig.PROJECT_ROOT or
projectRoot: publicRuntimeConfig.PROJECT_ROOT

Use in next-i18next

https://github.com/gurkerl83/next-i18next-serverless/blob/9834ff880031e5ef490ab4b8f84bec9f8c4195d5/src/config/create-config.ts#L77

The critical thing is that process.cwd() is not the root folder when deployed with NOW.

How do you think this can best be solved?

@ijjk
Copy link
Member

ijjk commented Feb 4, 2020

It looks like the above middleware could be applied in getInitialProps of Document as they are provided a similar context argument

@gurkerl83
Copy link
Contributor Author

Great catch, I will try that, thx!

@gurkerl83
Copy link
Contributor Author

Using the middleware in getInitialProps had worked. I`m not using the document middleware anymore. Thx again!

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants