Surendra Sharma

Surendra Sharma

Search This Blog

Showing posts with label headless. Show all posts
Showing posts with label headless. Show all posts

Thursday, August 31, 2023

Connection to Your Rendering Host Failed with a Body Exceeded 2MB Limit

In the ever-evolving landscape of digital experiences, Sitecore JSS (JavaScript Services) combined with Next.js has emerged as a powerful duo for building headless websites. This approach provides flexibility, scalability, and performance. However, as with any technology, challenges may arise. 

In this blog post, we'll delve into one such challenge: the "Connection to Your Rendering Host Failed with a Body Exceeded 2MB Limit" error and how to tackle it effectively.

Understanding the Error

We have deployed our Next.js app on Azure Web App and we started to get the “Connection to your rendering host failed with a Body exceeded 2mb limit error. Ensure the POST endpoint at URL https://mynextjs-sitecore-test.azurewebapp.net/api/editing/render has been enabled” error. Its typically occurs when a request made to the Sitecore rendering host exceeds the predefined request size limit. This limit is set at 2MB by default to prevent excessively large requests from overwhelming the server and causing performance issues.

When building a Sitecore JSS-based headless website with Next.js, it's common to transfer data between the front end (Next.js) and the back end (Sitecore) using API calls. These API calls may involve sending large payloads, especially when dealing with extensive content or complex data structures.

Solutions

Once you've diagnosed the issue, it's time to implement a solution. We try to solve it in lots of 
different way, but ultimately the solution that work for us is

• Open “\src\pages\api\editing\render.ts” file and change size from 2 MB to 50 MB as

export const config = {
api: {
bodyParser: {
sizeLimit: '50mb',
},
responseLimit: false,
},
};

• Open “\src\pages\api\editing\data\[key].ts” file and change size from 2 MB to 50 MB as

export const config = {
api: {
bodyParser: {
sizeLimit: '2mb',
},
responseLimit: false,
},
};

• Build and deploy your application, it should work now.

I hope this trick may solve your problem as well. Happy coding!

Saturday, February 18, 2023

When NOT to use Headless CMS

Introduction

Headless CMS is a popular technology that is used to manage and publish content across multiple platforms. However, it's not always the best choice for every website or application. In this blog post, I will explain when not to use a headless CMS and why.

  • Simple Websites with Minimal Content: If your website is small and doesn't require dynamic content, a headless CMS may be unnecessary. For instance, if your website has only a few pages, it's better to use a traditional CMS or a static site generator. You don't need the added complexity of a headless CMS for a simple website.
  • Small Development Teams with Limited Resources: While headless CMS platforms can offer many benefits, they can also be more complex to set up and maintain than traditional CMS. If your development team is small or lacks experience with headless CMS, it may be better to stick with a more familiar technology. Using a headless CMS can add unnecessary complexity to the development process.
  • Content-Heavy Websites with Complex Data Structures: Headless CMS platforms are designed to handle complex content models and data structures. However, if your website has relatively simple content needs, you may not need the added complexity of a headless CMS. In this case, a traditional CMS may be a better option. If your website doesn't require a complex content structure, there's no need to use a headless CMS.
  • Websites with Tight Deadlines: If you're working on a tight deadline, you may not have the time to learn and implement a headless CMS. Traditional CMS platforms are generally quicker to set up and easier to use, making them a better choice for fast turnarounds. If you're under time pressure, it's better to use a traditional CMS platform.
  • Websites with Tight Budgets: While headless CMS platforms can be a great choice for larger websites and enterprise-level applications, they can be more expensive to implement than traditional CMS. If you're working with a tight budget, it may be more cost-effective to stick with a more traditional approach. Using a traditional CMS can help you save money and still achieve your website goals.
  • Multiple Integrations: Traditional CMS may be a better choice if you need to perform multiple integrations in your CMS.
  • Customization: If you anticipate the need for extensive customization of the CMS for administrators or content authors, a traditional CMS might be more suitable than a headless one.

Conclusion: Headless CMS platforms are powerful tools that can help you manage and publish content across multiple platforms. However, they're not always the best choice for every website or application. By understanding when not to use a headless CMS, you can make a more informed decision and choose the technology that's right for your project.

Here is the Youtube video for the same




Friday, January 28, 2022

Sitecore JSS : Convert YML to JSON

Till yesterday, I knew that to provide content in Sitecore JSS I need to create YML file.

But today I learn that one can also create JSON file as well

Lets suppose we have following Graphql en.yml file

fields:

  pageTitle: GraphQL | Sitecore JSS

placeholders:

  jss-main:

  - componentName: ContentBlock

    fields:

      heading: Using GraphQL with JSS

      content: |

        <p>This is a live example of using Integrated GraphQL and Connected GraphQL with a JSS app.

        For more information on GraphQL use in JSS, please see <a href="https://jss.sitecore.com" target="_blank" rel="noopener noreferrer">the documentation</a>.</p>

  - componentName: GraphQL-Layout

    placeholders:

      jss-graphql-layout:

      - componentName: GraphQL-IntegratedDemo

        fields:

          sample1: Hello integrated GraphQL world!

          sample2:

            href: https://www.sitecore.com

            target: _blank

            text: GraphQL lets you get structured field data too

      - componentName: GraphQL-ConnectedDemo

        fields:

          sample1: Hello connected GraphQL world!

          sample2:

            href: https://www.sitecore.com

            target: _blank

            text: GraphQL lets you get structured field data too

 

I want to convert it to json file which can be easily accopalieshed by visiting https://onlineyamltools.com/convert-yaml-to-json as


I kept this json data in “testymltojson.json” file as 



He is the complete code

{

    "fields": {

        "pageTitle": "GraphQL | Sitecore JSS - YML To JSON"

    },

    "placeholders": {

        "jss-main": [

            {

                "componentName": "ContentBlock",

                "fields": {

                    "heading": "Using GraphQL with JSS - YML To JSON",

                    "content": "<p>This is a live example of using Integrated GraphQL and Connected GraphQL with a JSS app.\nFor more information on GraphQL use in JSS, please see <a href=\"https://jss.sitecore.com\" target=\"_blank\" rel=\"noopener noreferrer\">the documentation</a>.</p>\n"

                }

            },

            {

                "componentName": "GraphQL-Layout",

                "placeholders": {

                    "jss-graphql-layout": [

                        {

                            "componentName": "GraphQL-IntegratedDemo",

                            "fields": {

                                "sample1": "Hello integrated GraphQL world!",

                                "sample2": {

                                    "href": "https://www.sitecore.com",

                                    "target": "_blank",

                                    "text": "GraphQL lets you get structured field data too"

                                }

                            }

                        },

                        {

                            "componentName": "GraphQL-ConnectedDemo",

                            "fields": {

                                "sample1": "Hello connected GraphQL world!",

                                "sample2": {

                                    "href": "https://www.sitecore.com",

                                    "target": "_blank",

                                    "text": "GraphQL lets you get structured field data too"

                                }

                            }

                        }

                    ]

                }

            }

        ]

    }

}


So if you deployed it to Sitecore, this json file will create its item as


Short tip but very useful!!!


Saturday, February 2, 2019

Sitecore Headless architecture in Ravana ways


With version 9.1, Sitecore officially started to support JSS(Java Script Services) which bring a capability of true headless CMS.
 
But headless is still a new concept for many developers and if you questioned them during interview what is headless, many developers just started to feel uncomfortable.

This article may help you to understand headless architecture through Ravana(Wikipedia) way.

In India we have one of the greatest epic called Ramayana.

In short it's an epic about lord Rama, Sita, Ravana etc. This Ravana is very interesting mythological character and help me to understand headless architecture.

In many temples, Ravana showed with all his weapons and with 10 heads as

Ravan
Ravan

Ravana kidnapped Sita, so there was a war between Rama and Ravana. During that war Rama cut his head as

Headless Ravan
Headless Ravan


But Ravana was blessed with boon from Brahma and nobody can kill him in normal way.

Here you can imagine Ravana legs as Sitecore databases, his middle body as Sitecore XP and his all weapons represented as xConnect, Sitecore analytics and services, etc. 

But any living creature can't be survive well without any head. Similarly Sitecore can be headless but your final product or website can't be headless. It must have at least one or more head. It's something like

Depicting Sitecore and Ravan

Ravana had 10 heads which were different in look and shape. Each head was master in one field but ultimately, they all were face of Ravana. 

Similarly there are different front-end technologies with different features and uses. Where front end technologies can be angular, React, Vue.js, knockout, ASP.Net, MVC, Ruby etc. 

In short Ravana body represent Sitecore backend parts while his heads represent front end technologies.

That’s it.

I hope Ravana's character help you to understand Headless architecture. So next time someone ask you about headless explain him through Ravana's way.

Happy headless.