mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 23:32:38 +00:00
fix(nitro): use random port for stackblitz (#1666)
This commit is contained in:
parent
c8b07a6a1c
commit
3cd4494770
@ -34,7 +34,7 @@
|
|||||||
"rc9": "^1.2.0",
|
"rc9": "^1.2.0",
|
||||||
"scule": "^0.2.1",
|
"scule": "^0.2.1",
|
||||||
"semver": "^7.3.5",
|
"semver": "^7.3.5",
|
||||||
"std-env": "3.0.0-0",
|
"std-env": "^3.0.0",
|
||||||
"ufo": "^0.7.9",
|
"ufo": "^0.7.9",
|
||||||
"unctx": "^1.0.2",
|
"unctx": "^1.0.2",
|
||||||
"untyped": "^0.2.11"
|
"untyped": "^0.2.11"
|
||||||
|
@ -63,7 +63,7 @@
|
|||||||
"rollup-plugin-visualizer": "^5.5.2",
|
"rollup-plugin-visualizer": "^5.5.2",
|
||||||
"serve-placeholder": "^1.2.4",
|
"serve-placeholder": "^1.2.4",
|
||||||
"serve-static": "^1.14.1",
|
"serve-static": "^1.14.1",
|
||||||
"std-env": "3.0.0-0",
|
"std-env": "^3.0.0",
|
||||||
"table": "^6.7.2",
|
"table": "^6.7.2",
|
||||||
"ufo": "^0.7.9",
|
"ufo": "^0.7.9",
|
||||||
"unenv": "^0.4.0",
|
"unenv": "^0.4.0",
|
||||||
|
@ -4,14 +4,18 @@ import { tmpdir } from 'os'
|
|||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import { mkdirSync } from 'fs'
|
import { mkdirSync } from 'fs'
|
||||||
import { threadId, parentPort } from 'worker_threads'
|
import { threadId, parentPort } from 'worker_threads'
|
||||||
|
import { isWindows, provider } from 'std-env'
|
||||||
import { handle } from '../server'
|
import { handle } from '../server'
|
||||||
|
|
||||||
const server = new Server(handle)
|
const server = new Server(handle)
|
||||||
|
|
||||||
function createSocket () {
|
function getAddress () {
|
||||||
const isWin = process.platform === 'win32'
|
// https://github.com/nuxt/framework/issues/1636
|
||||||
|
if (provider === 'stackblitz' || process.env.NITRO_NO_UNIX_SOCKET) {
|
||||||
|
return '0'
|
||||||
|
}
|
||||||
const socketName = `worker-${process.pid}-${threadId}.sock`
|
const socketName = `worker-${process.pid}-${threadId}.sock`
|
||||||
if (isWin) {
|
if (isWindows) {
|
||||||
return join('\\\\.\\pipe\\nitro', socketName)
|
return join('\\\\.\\pipe\\nitro', socketName)
|
||||||
} else {
|
} else {
|
||||||
const socketDir = join(tmpdir(), 'nitro')
|
const socketDir = join(tmpdir(), 'nitro')
|
||||||
@ -20,7 +24,13 @@ function createSocket () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const socketPath = createSocket()
|
const listenAddress = getAddress()
|
||||||
server.listen(socketPath, () => {
|
server.listen(listenAddress, () => {
|
||||||
parentPort.postMessage({ event: 'listen', address: { socketPath } })
|
const _address = server.address()
|
||||||
|
parentPort.postMessage({
|
||||||
|
event: 'listen',
|
||||||
|
address: typeof _address === 'string'
|
||||||
|
? { socketPath: _address }
|
||||||
|
: `http://localhost:${_address.port}`
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
18
yarn.lock
18
yarn.lock
@ -2893,7 +2893,7 @@ __metadata:
|
|||||||
rc9: ^1.2.0
|
rc9: ^1.2.0
|
||||||
scule: ^0.2.1
|
scule: ^0.2.1
|
||||||
semver: ^7.3.5
|
semver: ^7.3.5
|
||||||
std-env: 3.0.0-0
|
std-env: ^3.0.0
|
||||||
ufo: ^0.7.9
|
ufo: ^0.7.9
|
||||||
unbuild: latest
|
unbuild: latest
|
||||||
unctx: ^1.0.2
|
unctx: ^1.0.2
|
||||||
@ -2972,7 +2972,7 @@ __metadata:
|
|||||||
rollup-plugin-visualizer: ^5.5.2
|
rollup-plugin-visualizer: ^5.5.2
|
||||||
serve-placeholder: ^1.2.4
|
serve-placeholder: ^1.2.4
|
||||||
serve-static: ^1.14.1
|
serve-static: ^1.14.1
|
||||||
std-env: 3.0.0-0
|
std-env: ^3.0.0
|
||||||
table: ^6.7.2
|
table: ^6.7.2
|
||||||
ufo: ^0.7.9
|
ufo: ^0.7.9
|
||||||
unbuild: latest
|
unbuild: latest
|
||||||
@ -18931,13 +18931,6 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"std-env@npm:3.0.0-0":
|
|
||||||
version: 3.0.0-0
|
|
||||||
resolution: "std-env@npm:3.0.0-0"
|
|
||||||
checksum: 0a0b5daaafeadc570ebaa7b36603f3a04f43a6eb893feeeaaae3caa3d0a2fa6f3a5c0f9376bd8245c73d289b2c3b2176de0daa4f75de0f2c6c125e32a95880d8
|
|
||||||
languageName: node
|
|
||||||
linkType: hard
|
|
||||||
|
|
||||||
"std-env@npm:^2.2.1, std-env@npm:^2.3.0":
|
"std-env@npm:^2.2.1, std-env@npm:^2.3.0":
|
||||||
version: 2.3.1
|
version: 2.3.1
|
||||||
resolution: "std-env@npm:2.3.1"
|
resolution: "std-env@npm:2.3.1"
|
||||||
@ -18947,6 +18940,13 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"std-env@npm:^3.0.0":
|
||||||
|
version: 3.0.0
|
||||||
|
resolution: "std-env@npm:3.0.0"
|
||||||
|
checksum: 5a9b91e853e869780c3af90c3d8e4325497da839084daa2edcc5b6ad3585bfd866ecb54d16143a5abbbd0e02ddf05fdd6bcc6e5068638c820652178eb435315c
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"stream-browserify@npm:^2.0.1":
|
"stream-browserify@npm:^2.0.1":
|
||||||
version: 2.0.2
|
version: 2.0.2
|
||||||
resolution: "stream-browserify@npm:2.0.2"
|
resolution: "stream-browserify@npm:2.0.2"
|
||||||
|
Loading…
Reference in New Issue
Block a user