-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add proxy support #32
Conversation
4f96371
to
4bc559e
Compare
4bc559e
to
a13cb07
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
commands/reshowcase
Outdated
const port = getPort(); | ||
const durationLabel = "[Reshowcase] Watch and serve started. Duration"; | ||
console.time(durationLabel); | ||
const clientPort = getPort(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clientPort
is a bit weird naming as a port is always on the server. What about userFacingPort
? Or userPort
. Or just port
as before (the esbuild one is an internal detail really)
commands/reshowcase
Outdated
.then((_serveResult) => { | ||
console.timeEnd(durationLabel); | ||
console.error("[Reshowcase] Watch mode started on port:", port); | ||
.then((s) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd name s
-> esbuildServer
I also realized that we need socket support for this. I'll add it before merging |
commands/reshowcase
Outdated
@@ -225,11 +226,55 @@ if (isBuild) { | |||
process.exit(1); | |||
}) | |||
.then((ctx) => { | |||
return ctx.serve({ port: port, servedir: outputPath }); | |||
return ctx.serve({ servedir: outputPath }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kind of minor: as esbuild will pick up a random port if none is defined, and the esbuild server is created before the proxy one, maybe we could set esbuild port as port + 1
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To ensure that esbuild doesn't accidentally take useful port?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah to make sure that esbuild picks port 3000 and user passes 3000 as well from command line. I think it's very unlikely though if esbuild picks the first available port... feel free to ignore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logging should be improved, and script itself should be more robust, but we can improve it step-by-step
commands/reshowcase
Outdated
...options.headers, | ||
...(rewrite.changeOrigin ? { host: `${options.host}:${options.port}` } : {}) | ||
}; | ||
console.info(`forwarding ${req.url} to ${options.host}:${options.port}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added these logs, but maybe it's too verbose. Probably should hide behind some flag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should add [Reshowcase]
as the other logs?
commands/reshowcase
Outdated
proxyReq.on("error", err => { | ||
console.error("Proxy request error:", err); | ||
res.writeHead(500, { "Content-Type": "text/plain" }); | ||
res.end("Internal Server Error"); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should show less details here as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in this case we want to know as much as possible. Would definitely keep them (the same comment about [Reshowcase]
prefix applies).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason, live reload doesn't work for me. I have tried this branch, esbuild
branch, working locally, on nspawn, with async/await... nothing.
It's strange because i use the same mechanism for react-alicante workshop and over there it works great.
commands/reshowcase
Outdated
...options.headers, | ||
...(rewrite.changeOrigin ? { host: `${options.host}:${options.port}` } : {}) | ||
}; | ||
console.info(`forwarding ${req.url} to ${options.host}:${options.port}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should add [Reshowcase]
as the other logs?
commands/reshowcase
Outdated
if (rewrite) { | ||
if (rewrite.socketPath) { | ||
options.socketPath = rewrite.socketPath; | ||
console.info(`forwarding ${req.url} to ${options.socketPath}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should add [Reshowcase]
as the other logs?
commands/reshowcase
Outdated
proxyReq.on("error", err => { | ||
console.error("Proxy request error:", err); | ||
res.writeHead(500, { "Content-Type": "text/plain" }); | ||
res.end("Internal Server Error"); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in this case we want to know as much as possible. Would definitely keep them (the same comment about [Reshowcase]
prefix applies).
commands/reshowcase
Outdated
|
||
server.listen(port, error => { | ||
if (error) { | ||
return console.error(error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Reshowcase]
prefix.
commands/reshowcase
Outdated
return console.error(error) | ||
} | ||
|
||
console.log(`[Reshowcase] Server listening on port ${port}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we mention something about "watch mode"? The previous message was Watch and serve started.
. Also the timings were useful (imo).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, would be useful to print full URL so that one can cmd-click from the terminal and open the browser tab directly, if desired.
After looking at it, I am not sure I understand at all how it supposed to work. Script is completely dependent on |
Ah, great point! That seems to be the issue. If I run in separate terminals:
Then it works fine. I think this means we have to keep the esbuild command running, and we have to move away from the "Dune does everything" approach we were following. Let me know if I can help somehow! |
I added a comment for the live reload in the upstream PR because it's probably out of the scope in this one. |
I'll merge this to upstream PR and continue with fixes there to avoid conflicts |
This PR adds basic support for proxying by putting node http server in front of esbuild