Skip to content

Commit

Permalink
feat: support http2
Browse files Browse the repository at this point in the history
close #424
  • Loading branch information
yyx990803 committed Jun 22, 2020
1 parent df7f335 commit f4fd832
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
12 changes: 4 additions & 8 deletions src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ console.log('[vite] connecting...')

declare var __VUE_HMR_RUNTIME__: HMRRuntime

const socketProtocol = location.protocol === 'https:' ? 'wss' : 'ws'
const socket = new WebSocket(`${socketProtocol}://${location.host}`)
const socket = new WebSocket(`ws://${location.hostname}:24678`)

function warnFailedFetch(err: Error, path: string | string[]) {
if (!err.message.match('fetch')) {
Expand Down Expand Up @@ -140,12 +139,9 @@ socket.addEventListener('message', async ({ data }) => {
socket.addEventListener('close', () => {
console.log(`[vite] server connection lost. polling for restart...`)
setInterval(() => {
new WebSocket(`${socketProtocol}://${location.host}`).addEventListener(
'open',
() => {
location.reload()
}
)
new WebSocket(`ws://${location.host}`).addEventListener('open', () => {
location.reload()
})
}, 1000)
})

Expand Down
2 changes: 1 addition & 1 deletion src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function resolveServer(
requestListener: RequestListener
) {
if (https) {
return require('https').createServer(
return require('http2').createSecureServer(
resolveHttpsConfig(httpsOption),
requestListener
)
Expand Down
2 changes: 1 addition & 1 deletion src/node/server/serverPluginHmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export const hmrPlugin: ServerPlugin = ({
})

// start a websocket server to send hmr notifications to the client
const wss = new WebSocket.Server({ server })
const wss = new WebSocket.Server({ port: 24678 })

wss.on('connection', (socket) => {
debugHmr('ws client connected')
Expand Down

0 comments on commit f4fd832

Please sign in to comment.