Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

How to add forward headers for _next/data/*  #682

@jjanssen

Description

@jjanssen

Describe the issue

Right now we have a site which is mostly based upon getServerSideProps to connect to a large instance of a CMS.

I managed to forward the Authorization and Host in a default scenario. Authorization as I also have basic authentication implemented on a test and acceptance environment. The host as I'm required to do some additional filtering in a multisite environment. There are static pages, but other than that pages/[...slug].jsmanages most of the routing to connect to the CMS.

When accessing the URL directly my hostname gets passed on correctly. But when navigating throughout, the client-side is making a call to /_next/data/something in order to full-fill the server-side call. Yet now my host isn't forwarded anymore as I'm matching the /_next/data/ behaviour in CloudFront.

I'm also able to configure forwarding headers for api/* as per the example in the README.md.
But somehow I'm not able to pass these in the assumption I have to enter _next/data/* to match the behaviour pattern:

    cloudfront:
      priceClass: "PriceClass_100"
      defaults:
        forward:
          headers:
            [
              Authorization,
              Host
            ]
      api/*:
        forward:
          headers:
            [              
              Authorization,
              Host
            ]
      _next/data/*:
        forward:
          headers:
            [
              Authorization,
              Host
            ]

If I would have configured the following it would end-up throwing the following message:

  Error: CloudFront input failed validation. Could not find next.js pages for "_next/data/*"
    at NextjsComponent.validatePathPatterns (/Users/j.janssen/.serverless/components/registry/npm/@sls-next/serverless-component@1.18.0-alpha.7/node_modules/@sls-next/serverless-component/dist/component.js:140:13)
    at NextjsComponent.<anonymous> (/Users/j.janssen/.serverless/components/registry/npm/@sls-next/serverless-component@1.18.0-alpha.7/node_modules/@sls-next/serverless-component/dist/component.js:409:12)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/j.janssen/.serverless/components/registry/npm/@sls-next/serverless-component@1.18.0-alpha.7/node_modules/@sls-next/serverless-component/dist/component.js:15:26)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:94:5)

  39s › my-fancy-website-tst › Error: CloudFront input failed validation. Could not find next.js pages for "_next/data/*"

I have been looking around at other issues and #617 seems identical, except the upgrade didn't make a difference.

Versions

  • OS/Environment: OSX 10.14.6
  • @sls-next/serverless-component version: 1.18.0-alpha.7
  • Next.js version: 9.5.0

Checklist

  • You have reviewed the README and FAQs, which answers several common questions.
  • Please first try using the latest @sls-next/serverless-component release version, which may have already fixed your issue. Note that the old serverless-next.js component and the serverless-next.js plugin are deprecated and no longer maintained.

How-to reproduce

A basic setup can be found here: https://github.com/jjanssen/serverless-next-bare-example/
A yarn install and serverless would already do the trick and has a fragment of the _next/data commented out.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions