question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getServerSideProps data urls don't respect assetPrefix

See original GitHub issue

Bug report

Describe the bug

I have assetPrefix set because we are hosting multiple applications on the same domain and use a proxy to route paths.

assetPrefix = "reports"

The static asset urls are correct. Such as /reports/_next/static/development/pages/_app.js?ts=1587171521639.

However, the data fetching URLs are NOT including the prefix: /_next/data/development/reports/appointments/2020-03-18/2020-04-17.json.

To Reproduce

  • Set assetPrefix to anything
  • Create a page with getServerSideProps
  • use the router (or Link) to go to that page on the client
  • Observe in the network request inspector that the data urls do not include the assetPrefix.

Expected behavior

I would expect the assetPrefix to apply to ALL asset urls that start with _next/

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
pueyo5commented, Aug 11, 2020

Please use the new basePath support instead of assetPrefix in Next.js 9.5.1+ for this use case!

@Timer In our case, this is not possible. The basePath is expecting a subfolder, and we want to use a subdomain. We are using https://cdn.domain.com and for the proposed solution we have to use https://domain.com/cdn.

Can this issue be reopened or do you want me to create a new one?

4reactions
daveskybetcommented, Apr 30, 2020

Poking about with the code (i’m no expert in the codebase), here seems to be the culprit:

https://github.com/zeit/next.js/blob/canary/packages/next/next-server/lib/router/router.ts#L94

Which seems to add an experimental basePath if exists, rather than the assetPrefix as I would have expected (as gets added to the preload tags for the json files)

A quick addition of the assetPrefix to this line fixes my problem (with an ssg site using getStaticProps), but i’m questioning whether we’re misunderstanding the expected behaviour (with the basePath addition)?

Read more comments on GitHub >

github_iconTop Results From Across the Web

getServerSideProps data urls don't respect assetPrefix #11992
I have assetPrefix set because we are hosting multiple applications on the same domain and use a proxy to route paths. assetPrefix =...
Read more >
Data Fetching: getServerSideProps - Next.js
getServerSideProps returns JSON which will be used to render the page. All this work will be handled automatically by Next.js, so you don't...
Read more >
Next.js: The Good, Bad and Ugly - An Idiosyncratic Blog
If you've never heard about Next.js, it's a framework built on top ... The _next/data path does not respect assetPrefix or basePath value....
Read more >
Next.js - Full Context Review
it will die on the internal. _next/data. requests for the json page data because that folder doesn't respect the. assetPrefix. nor the.
Read more >
@sentry-internal/typescript | Yarn - Package Manager
Links. Official SDK Docs · TypeDoc ... "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found