Skip to content

Commit

Permalink
feat: support configurable ws port and remote development (#429)
Browse files Browse the repository at this point in the history
Co-authored-by: Jeremy Press <[email protected]>
Co-authored-by: Jacky Zhao <[email protected]>
  • Loading branch information
3 people authored Aug 28, 2023
1 parent 4b89202 commit b6b1dab
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ tsconfig.tsbuildinfo
.obsidian
.quartz-cache
private/
.replit
replit.nix
10 changes: 10 additions & 0 deletions quartz/cli/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ export const BuildArgv = {
default: 8080,
describe: "port to serve Quartz on",
},
wsPort: {
number: true,
default: 3001,
describe: "port to use for WebSocket-based hot-reload notifications",
},
remoteDevHost: {
string: true,
default: "",
describe: "A URL override for the websocket connection if you are not developing on localhost",
},
bundleInfo: {
boolean: true,
default: false,
Expand Down
2 changes: 1 addition & 1 deletion quartz/cli/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ export async function handleBuild(argv) {
return serve()
})
server.listen(argv.port)
const wss = new WebSocketServer({ port: 3001 })
const wss = new WebSocketServer({ port: argv.wsPort })
wss.on("connection", (ws) => connections.push(ws))
console.log(
chalk.cyan(
Expand Down
8 changes: 7 additions & 1 deletion quartz/plugins/emitters/componentResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,18 @@ function addGlobalPageResources(
document.dispatchEvent(event)`)
}

let wsUrl = `ws://localhost:${ctx.argv.wsPort}`

if (ctx.argv.remoteDevHost) {
wsUrl = `wss://${ctx.argv.remoteDevHost}:${ctx.argv.wsPort}`
}

if (reloadScript) {
staticResources.js.push({
loadTime: "afterDOMReady",
contentType: "inline",
script: `
const socket = new WebSocket('ws://localhost:3001')
const socket = new WebSocket('${wsUrl}'')
socket.addEventListener('message', () => document.location.reload())
`,
})
Expand Down
2 changes: 2 additions & 0 deletions quartz/util/ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export interface Argv {
output: string
serve: boolean
port: number
wsPort: number
remoteDevHost?: string
concurrency?: number
}

Expand Down

0 comments on commit b6b1dab

Please sign in to comment.