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

Support base path parameter from next config #79

Merged
merged 1 commit into from Jul 27, 2021

Conversation

yakovlev-alexey
Copy link
Contributor

Changes are made to support both injecting a custom base path through options and pulling base path from local Next config from injected Next Server instance. Explicit base path in RenderModule options is used over the one from Next config if specified.

This PR closes #78.

@@ -23,6 +23,15 @@ export class RenderModule {
await next.prepare();
}

const nextConfig = (next as any).nextConfig;
const nextServer = (next as any).server;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Depending on Next version (^9 or ^10) nextConfig property may be in a different location. In older Next ^9 we have direct access to it with proper typings. In Next ^10 I wasn't able to find any way to access the config from injected Next Server instance, however there is a way to get it from an untyped server property. Tested this on reproduction repo provided in #78 with Next 10.2 and on an enterprise project with Next 9.5.

? nextConfig.basePath
: nextServer.nextConfig.basePath;

const config = { basePath, ...options };
Copy link
Contributor Author

Choose a reason for hiding this comment

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

basePath from RenderModule options has higher priority (in case you might want to override the base path in next.config.js for internal endpoints (eg your Nest application is deployed behind a proxy)).

@kyle-mccarthy
Copy link
Owner

Thanks for the contribution - this looks good to me 👍

@kyle-mccarthy kyle-mccarthy merged commit b391eb5 into kyle-mccarthy:master Jul 27, 2021
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.

Next basePath configuration support
2 participants