Commit f0b6d0a1 authored by Lukáš Huvar's avatar Lukáš Huvar Committed by Joe Haddad

Fix custom page extension in development (#8446)

* Fix page extension in development

* Remove un-used file

* Fix standard
parent 5ad0ea8e
import Server from 'next-server/dist/server/next-server'
import { join, relative, extname } from 'path'
import { join, relative } from 'path'
import HotReloader from './hot-reloader'
import { route } from 'next-server/dist/server/router'
import { PHASE_DEVELOPMENT_SERVER } from 'next-server/constants'
......@@ -129,8 +129,10 @@ export default class DevServer extends Server {
let pageName = '/' + relative(pagesDir, fileName).replace(/\\+/g, '/')
const pageExt = extname(pageName)
pageName = pageName.slice(0, -pageExt.length)
pageName = pageName.replace(
new RegExp(`\\.+(?:${this.nextConfig.pageExtensions.join('|')})$`),
''
)
pageName = pageName.replace(/\/index$/, '') || '/'
......
module.exports = {
target: 'server',
pageExtensions: ['page.js']
}
const Page = ({ pid }) => <div>{`Post - ${pid}`}</div>
Page.getInitialProps = ({ query }) => {
return { pid: query.pid }
}
export default Page
/* eslint-env jest */
/* global jasmine */
import { join } from 'path'
import {
nextBuild,
nextStart,
findPort,
launchApp,
killApp,
renderViaHTTP,
killAll,
File
} from 'next-test-utils'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 1
const appDir = join(__dirname, '..')
let appPort
let app
const runTests = () => {
it('should work with normal page', async () => {
const html = await renderViaHTTP(appPort, '/blog')
expect(html).toContain('Blog - CPE')
})
it('should work dynamic page', async () => {
const html = await renderViaHTTP(appPort, '/blog/nextjs')
expect(html).toContain('Post - nextjs')
})
}
describe('Custom page extension', () => {
describe('dev mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
})
describe('production mode', () => {
beforeAll(async () => {
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => killAll(app))
runTests()
})
describe('serverless mode', () => {
const nextConfig = new File(join(appDir, 'next.config.js'))
beforeAll(async () => {
nextConfig.replace('server', 'serverless')
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
nextConfig.restore()
})
runTests()
})
})
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