nksaraf / vinxi

The Full Stack JavaScript SDK
https://vinxi.vercel.app
MIT License
1.33k stars 57 forks source link

Programatically restart dev server #285

Closed shiro closed 2 months ago

shiro commented 2 months ago

Hello, I was wondering if the function for restarting the dev server is exported?

I would like to call it from my vite plugin. If it's not exported, where would it have to be moved (in the filestructure), currently it's sitting inside the cli handler, so that would prob. be messy right?

shiro commented 2 months ago

After thinking about it for a while, it seems like only cli.mjs holds a reference to the app (which we need for a server restart), and since it's not a singelton, this could be tricky.

I actually found an easier hack to restart the server, in case anyone needs it:

fs.utimesSync("./app.config.ts", time, time);

Just bump the last_modified timestamp on the config, since there's a watcher on it :D

Feel free to close the issue if it's out of scope :+1:

nksaraf commented 2 months ago

Yeah I hve wondered if I should expose it somehow via app, but the app instance changes when that reload happens. But updating the time on the config file is actully a pretty clean way to do it as long as we can clean up and close things before the restart.. but that's on vinxi to do