Yes, it is possible to utilize Server-side rendering (SSR) in NextJS 13 in a location other than the recently introduced "app" directory. NextJS allows developers to configure the location of the file responsible for server-side rendering using the serverRuntimeConfig
option in the Next.js configuration file (next.config.js
).
For example, if you want to create a custom SSR file named custom-ssr.js
in the root directory of your project, you can add the following lines of code to your next.config.js
file:
module.exports = {
serverRuntimeConfig : {
// Point to the custom SSR file location
mySsr: './custom-ssr.js',
},
}
After that, you can use the mySsr
key to reference the custom SSR file anywhere in your NextJS application.
import { getServerSideProps } from 'next';
import getConfig from 'next/config';
const { serverRuntimeConfig } = getConfig();
export const getServerSideProps = async () => {
const { mySsr } = serverRuntimeConfig;
// Call the custom SSR function
const result = await mySsr();
return {
props: {
data: result,
},
};
};
By using this approach, you can easily organize application files in a way that is more suitable for your project requirements.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-02-12 11:00:00 +0000
Seen: 15 times
Last updated: Aug 10 '21
What could be the reason for the node app not functioning on Namecheap hosting?
How does rate limiting work for Azure Function in .NET 7?
How to identify the screen location of the mouse pointer in an electron app?
What is missing since the androidmanifest.xml file is not present?
When attempting to launch my Android app, why does my AVD open YouTube instead?
How can I set up a subdomain for Apple app site association?