File tree Expand file tree Collapse file tree 4 files changed +19
-9
lines changed Expand file tree Collapse file tree 4 files changed +19
-9
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,9 @@ const defaultConfig = {
1818 onDemandEntries : {
1919 maxInactiveAge : 60 * 1000 ,
2020 pagesBufferLength : 2 ,
21- websocketPort : 0
21+ websocketPort : 0 ,
22+ websocketProxyPath : '/' ,
23+ websocketProxyPort : null
2224 }
2325}
2426
Original file line number Diff line number Diff line change @@ -1297,6 +1297,10 @@ module.exports = {
12971297 pagesBufferLength: 2 ,
12981298 // optionally configure a port for the onDemandEntries WebSocket, not needed by default
12991299 websocketPort: 3001 ,
1300+ // optionally configure a proxy path for the onDemandEntries WebSocket, not need by default
1301+ websocketProxyPath: ' /hmr' ,
1302+ // optionally configure a proxy port for the onDemandEntries WebSocket, not need by default
1303+ websocketProxyPort: 7002 ,
13001304 },
13011305}
13021306` ` `
Original file line number Diff line number Diff line change 33import Router from 'next/router'
44import fetch from 'unfetch'
55
6- const { hostname } = location
6+ const { hostname, protocol } = location
7+ const wsProtocol = protocol . includes ( 'https' ) ? 'wss' : 'ws'
78const retryTime = 5000
89let ws = null
910let lastHref = null
@@ -19,7 +20,7 @@ export default async ({ assetPrefix }) => {
1920 }
2021
2122 return new Promise ( resolve => {
22- ws = new WebSocket ( `ws ://${ hostname } :${ process . env . NEXT_WS_PORT } ` )
23+ ws = new WebSocket ( `${ wsProtocol } ://${ hostname } :${ process . env . NEXT_WS_PORT } ${ process . env . NEXT_WS_PROXY_PATH } ` )
2324 ws . onopen = ( ) => resolve ( )
2425 ws . onclose = ( ) => {
2526 setTimeout ( async ( ) => {
Original file line number Diff line number Diff line change @@ -164,10 +164,13 @@ export default class HotReloader {
164164 return del ( join ( this . dir , this . config . distDir ) , { force : true } )
165165 }
166166
167- addWsPort ( configs ) {
168- configs [ 0 ] . plugins . push ( new webpack . DefinePlugin ( {
169- 'process.env.NEXT_WS_PORT' : this . wsPort
170- } ) )
167+ addWsConfig ( configs ) {
168+ const { websocketProxyPath, websocketProxyPort } = this . config . onDemandEntries
169+ const opts = {
170+ 'process.env.NEXT_WS_PORT' : websocketProxyPort || this . wsPort ,
171+ 'process.env.NEXT_WS_PROXY_PATH' : JSON . stringify ( websocketProxyPath )
172+ }
173+ configs [ 0 ] . plugins . push ( new webpack . DefinePlugin ( opts ) )
171174 }
172175
173176 async getWebpackConfig ( ) {
@@ -200,7 +203,7 @@ export default class HotReloader {
200203 } )
201204
202205 const configs = await this . getWebpackConfig ( )
203- this . addWsPort ( configs )
206+ this . addWsConfig ( configs )
204207
205208 const multiCompiler = webpack ( configs )
206209
@@ -229,7 +232,7 @@ export default class HotReloader {
229232 await this . clean ( )
230233
231234 const configs = await this . getWebpackConfig ( )
232- this . addWsPort ( configs )
235+ this . addWsConfig ( configs )
233236
234237 const compiler = webpack ( configs )
235238
You can’t perform that action at this time.
0 commit comments