-
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
feat(space-nuxt-base): run tunnel on start up #75
Conversation
…ace-tool-plugins into feat/run-tunnel-on-start-up
export default defineNuxtModule({ | ||
setup(_options, nuxt) { | ||
const tunnelCommand = process.env.TUNNEL_COMMAND; | ||
if (process.env.NODE_ENV !== 'development' || !tunnelCommand) { |
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.
Hey @eunjae-lee this might not be ready yet, I am just leaving comments as I am OOO tomorrow, but not to block you.
nit: process.env.NODE_ENV !== 'development'
is this check needed? From what I understood, the listen
hook will only be triggered when dev server is loaded. But I might be missing something here.
question: What happens when the dev server is closed, will the tunnel still be running?
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 actually added the explanation in the PR description, but if the dev server is closed, the tunnel will be closed as well, because the tunnel is the child process of the dev server process. When the parent dies, the child dies as well. (horrific dev story)
process.env.NODE_ENV !== 'development'
-> I guess we won't really need it because listen
is for the dev server as you said, however, if we have this, the production build will not include the code within the if clause at all, and it means we won't include execa
dependency as well in the bundle output. I actually copied this https://github.com/nuxtus/localtunnel/blob/main/src/module.ts#L44, and I believe that's why they did so?
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.
😂😂
Totally missed the description sorry. I read it now, thank you for the details. Everything looks perfect. Can't wait to try it 🫰🏻
|
What?
This PR runs a tunnel on start up, if you have the
TUNNEL_COMMAND
environment variable.For example,
If not, nothing changes.
Why?
This helps you care less about running a tunnel when working on space / tool plugins. The tunnel will quit as well when you quit the dev server.
Implementation Details
close
hookI've tried this in order to quit the tunnel.
However, ctrl + c just quit the Nuxt app without triggering the
close
hook.And it's because it's called when "gracefully closing".
So
close
hook is not useful in our case.closing
If you stop the dev server with ctrl + c, the dev server process is killed, and that tunnel command is a child process of the dev server process. So it's automatically killed as well. So we don't need to take care of killing the tunnel.
restarting
If you modify nuxt.config.ts file, Nuxt will restart the app. It actually re-starts a process, meaning the previous process is killed, and so is the tunnel process.
So the current implementation should be enough.