Skip to content

Commit b6b1dab

Browse files
jeremypressJeremy Pressjackyzha0
authored
feat: support configurable ws port and remote development (#429)
Co-authored-by: Jeremy Press <[email protected]> Co-authored-by: Jacky Zhao <[email protected]>
1 parent 4b89202 commit b6b1dab

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ tsconfig.tsbuildinfo
77
.obsidian
88
.quartz-cache
99
private/
10+
.replit
11+
replit.nix

quartz/cli/args.js

+10
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ export const BuildArgv = {
7676
default: 8080,
7777
describe: "port to serve Quartz on",
7878
},
79+
wsPort: {
80+
number: true,
81+
default: 3001,
82+
describe: "port to use for WebSocket-based hot-reload notifications",
83+
},
84+
remoteDevHost: {
85+
string: true,
86+
default: "",
87+
describe: "A URL override for the websocket connection if you are not developing on localhost",
88+
},
7989
bundleInfo: {
8090
boolean: true,
8191
default: false,

quartz/cli/handlers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ export async function handleBuild(argv) {
402402
return serve()
403403
})
404404
server.listen(argv.port)
405-
const wss = new WebSocketServer({ port: 3001 })
405+
const wss = new WebSocketServer({ port: argv.wsPort })
406406
wss.on("connection", (ws) => connections.push(ws))
407407
console.log(
408408
chalk.cyan(

quartz/plugins/emitters/componentResources.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,18 @@ function addGlobalPageResources(
107107
document.dispatchEvent(event)`)
108108
}
109109

110+
let wsUrl = `ws://localhost:${ctx.argv.wsPort}`
111+
112+
if (ctx.argv.remoteDevHost) {
113+
wsUrl = `wss://${ctx.argv.remoteDevHost}:${ctx.argv.wsPort}`
114+
}
115+
110116
if (reloadScript) {
111117
staticResources.js.push({
112118
loadTime: "afterDOMReady",
113119
contentType: "inline",
114120
script: `
115-
const socket = new WebSocket('ws://localhost:3001')
121+
const socket = new WebSocket('${wsUrl}'')
116122
socket.addEventListener('message', () => document.location.reload())
117123
`,
118124
})

quartz/util/ctx.ts

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export interface Argv {
77
output: string
88
serve: boolean
99
port: number
10+
wsPort: number
11+
remoteDevHost?: string
1012
concurrency?: number
1113
}
1214

0 commit comments

Comments
 (0)