Commit be2e5a8c authored by Arunoda Susiripala's avatar Arunoda Susiripala

Use the realPathname for script tags in document.js

This will help us to fetch these scripts directly from a
static server since these paths are resolved.
parent f602f6dc
......@@ -67,10 +67,10 @@ export class Head extends Component {
render () {
const { head, styles, __NEXT_DATA__ } = this.context._documentProps
const { pathname, buildId, assetPrefix } = __NEXT_DATA__
const { realPathname, buildId, assetPrefix } = __NEXT_DATA__
return <head>
<link rel='preload' href={`${assetPrefix}/_next/${buildId}/page${pathname}`} as='script' />
<link rel='preload' href={`${assetPrefix}/_next/${buildId}/page${realPathname}`} as='script' />
<link rel='preload' href={`${assetPrefix}/_next/${buildId}/page/_error`} as='script' />
{this.getPreloadMainLinks()}
{(head || []).map((h, i) => React.cloneElement(h, { key: i }))}
......@@ -133,7 +133,7 @@ export class NextScript extends Component {
render () {
const { staticMarkup, __NEXT_DATA__ } = this.context._documentProps
const { pathname, buildId, assetPrefix } = __NEXT_DATA__
const { realPathname, buildId, assetPrefix } = __NEXT_DATA__
return <div>
{staticMarkup ? null : <script dangerouslySetInnerHTML={{
......@@ -147,7 +147,7 @@ export class NextScript extends Component {
}
`
}} />}
<script async type='text/javascript' src={`${assetPrefix}/_next/${buildId}/page${pathname}`} />
<script async type='text/javascript' src={`${assetPrefix}/_next/${buildId}/page${realPathname}`} />
<script async type='text/javascript' src={`${assetPrefix}/_next/${buildId}/page/_error`} />
{staticMarkup ? null : this.getScripts()}
</div>
......
......@@ -90,10 +90,18 @@ async function doRender (req, res, pathname, query, {
if (res.finished) return
// realPathname is pretty useful in the document.js
// In there, we include a proper valid resolved path.
// That helps us to server that JSON page directly from a static server.
// Basically, this is a requirment for next-export
const pageRealPath = await resolvePath(join(dir, 'pages', pathname))
const realPathname = pageRealPath.replace(join(dir, 'pages'), '')
const doc = createElement(Document, {
__NEXT_DATA__: {
props,
pathname,
realPathname,
query,
buildId,
buildStats,
......@@ -101,6 +109,7 @@ async function doRender (req, res, pathname, query, {
err: (err) ? serializeError(dev, err) : null
},
dev,
dir,
staticMarkup,
...docProps
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment