add experimental https support to next dev (#54016)

This adds an `--experimental-https` flag to `next dev` which will generate a self-signed certificate via [mkcert](https://github.com/FiloSottile/mkcert) and use it for the dev server.

also supports passing in pre-existing certs via `--experimental-https-cert` and `--experimental-https-key`

x-ref: https://github.com/vercel/next.js/discussions/33768 https://github.com/vercel/next.js/discussions/10935
This commit is contained in:
Zack Tanner
2023-08-19 01:04:06 +00:00
committed by GitHub
parent bb9db03a41
commit adc413b3fb
15 changed files with 505 additions and 58 deletions
@@ -0,0 +1,35 @@
import { createNextDescribe } from 'e2e-utils'
import https from 'https'
import { renderViaHTTP } from 'next-test-utils'
createNextDescribe(
'experimental-https-server (generated certificate)',
{
files: __dirname,
startCommand: 'yarn next dev --experimental-https',
skipStart: !process.env.CI,
},
({ next }) => {
if (!process.env.CI) {
console.warn('only runs on CI as it requires administrator privileges')
it('only runs on CI as it requires administrator privileges', () => {})
return
}
const agent = new https.Agent({
rejectUnauthorized: false,
})
it('should successfully load the app in app dir', async () => {
expect(next.url).toInclude('https://')
const html = await renderViaHTTP(next.url, '/1', undefined, { agent })
expect(html).toContain('Hello from App')
})
it('should successfully load the app in pages dir', async () => {
expect(next.url).toInclude('https://')
const html = await renderViaHTTP(next.url, '/2', undefined, { agent })
expect(html).toContain('Hello from Pages')
})
}
)