Unverified Commit cb290857 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix next start in serverless mode with public directory (#7541)

* Fix next start in serverless mode with public directory

* Add public folder to serverless test suite
parent fa45fa0a
...@@ -13,6 +13,7 @@ import { ...@@ -13,6 +13,7 @@ import {
PAGES_MANIFEST, PAGES_MANIFEST,
PHASE_PRODUCTION_SERVER, PHASE_PRODUCTION_SERVER,
SERVER_DIRECTORY, SERVER_DIRECTORY,
SERVERLESS_DIRECTORY,
} from '../lib/constants' } from '../lib/constants'
import { import {
getRouteMatcher, getRouteMatcher,
...@@ -322,7 +323,12 @@ export default class Server { ...@@ -322,7 +323,12 @@ export default class Server {
private generatePublicRoutes(): Route[] { private generatePublicRoutes(): Route[] {
const routes: Route[] = [] const routes: Route[] = []
const publicFiles = recursiveReadDirSync(this.publicDir) const publicFiles = recursiveReadDirSync(this.publicDir)
const serverBuildPath = join(this.distDir, SERVER_DIRECTORY) const serverBuildPath = join(
this.distDir,
this.nextConfig.target === 'serverless'
? SERVERLESS_DIRECTORY
: SERVER_DIRECTORY
)
const pagesManifest = require(join(serverBuildPath, PAGES_MANIFEST)) const pagesManifest = require(join(serverBuildPath, PAGES_MANIFEST))
publicFiles.forEach(path => { publicFiles.forEach(path => {
......
...@@ -31,6 +31,11 @@ describe('Serverless', () => { ...@@ -31,6 +31,11 @@ describe('Serverless', () => {
expect(html).toMatch(/Hello World/) expect(html).toMatch(/Hello World/)
}) })
it('should serve file from public folder', async () => {
const content = await renderViaHTTP(appPort, '/hello.txt')
expect(content.trim()).toBe('hello world')
})
it('should render the page with dynamic import', async () => { it('should render the page with dynamic import', async () => {
const html = await renderViaHTTP(appPort, '/dynamic') const html = await renderViaHTTP(appPort, '/dynamic')
expect(html).toMatch(/Hello!/) expect(html).toMatch(/Hello!/)
......
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