Unverified Commit 5bc4b368 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

[backport] Ensure setAssetPrefix updates config instance (#82165)

Backports https://github.com/vercel/next.js/pull/82160 to our next-15-4
release branch
parent 717dfb6e
...@@ -1707,7 +1707,8 @@ export default abstract class Server< ...@@ -1707,7 +1707,8 @@ export default abstract class Server<
): Promise<void> ): Promise<void>
public setAssetPrefix(prefix?: string): void { public setAssetPrefix(prefix?: string): void {
this.renderOpts.assetPrefix = prefix ? prefix.replace(/\/$/, '') : '' this.nextConfig.assetPrefix = prefix ? prefix.replace(/\/$/, '') : ''
this.renderOpts.assetPrefix = this.nextConfig.assetPrefix
} }
protected prepared: boolean = false protected prepared: boolean = false
......
import { nextTestSetup } from 'e2e-utils'
describe('app-dir absolute assetPrefix', () => {
const { next } = nextTestSetup({
files: __dirname,
nextConfig: {
assetPrefix: 'https://example.vercel.sh/',
},
})
it('bundles should return 200 on served assetPrefix', async () => {
const $ = await next.render$('/')
let bundles = []
for (const script of $('script').toArray()) {
const { src } = script.attribs
if (src?.includes('https://example.vercel.sh/_next/static')) {
bundles.push(src)
}
}
expect(bundles.length).toBeGreaterThan(0)
for (const src of bundles) {
// Remove hostname to check if pathname is still used for serving the bundles
const bundlePathWithoutHost = decodeURI(new URL(src).pathname)
const { status } = await next.fetch(bundlePathWithoutHost)
expect(status).toBe(200)
}
})
})
...@@ -3,6 +3,9 @@ import { nextTestSetup } from 'e2e-utils' ...@@ -3,6 +3,9 @@ import { nextTestSetup } from 'e2e-utils'
describe('app-dir absolute assetPrefix', () => { describe('app-dir absolute assetPrefix', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
nextConfig: {
assetPrefix: 'https://example.vercel.sh/custom-asset-prefix',
},
}) })
it('bundles should return 200 on served assetPrefix', async () => { it('bundles should return 200 on served assetPrefix', async () => {
......
module.exports = {
assetPrefix: 'https://example.vercel.sh/custom-asset-prefix',
}
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