Skip to content

fix: serve static files from basePath #1850

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/runtime/src/helpers/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,12 @@ export const movePublicFiles = async ({
appDir,
outdir,
publish,
basePath,
}: {
appDir: string
outdir?: string
publish: string
basePath: string
}): Promise<void> => {
// `outdir` is a config property added when using Next.js with Nx. It's typically
// a relative path outside of the appDir, e.g. '../../dist/apps/<app-name>', and
Expand All @@ -447,6 +449,6 @@ export const movePublicFiles = async ({
// directory from the original app directory.
const publicDir = outdir ? join(appDir, outdir, 'public') : join(appDir, 'public')
if (existsSync(publicDir)) {
await copy(publicDir, `${publish}/`)
await copy(publicDir, `${publish}${basePath}/`)
}
}
2 changes: 1 addition & 1 deletion packages/runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ const plugin: NetlifyPlugin = {
await generateFunctions(constants, appDir, apiRoutes)
await generatePagesResolver(constants)

await movePublicFiles({ appDir, outdir, publish })
await movePublicFiles({ appDir, outdir, publish, basePath })

await patchNextFiles(appDir)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ describe('i18n-ignore-rewrite-source-locale with basepath', () => {
})
})
afterAll(() => next.destroy())
// NTL Fail
test.skip.each(locales)('get public file by skipping locale in rewrite, locale: %s', async (locale) => {
test.each(locales)('get public file by skipping locale in rewrite, locale: %s', async (locale) => {
const res = await renderViaHTTP(next.url, `/basepath${locale}/rewrite-files/file.txt`)
expect(res).toContain('hello from file.txt')
})
Expand Down