Skip to content
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 watcher on dev command to restart server on code changes #95

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

GAllen98
Copy link
Contributor

Also added a flag to disable the watcher

@GAllen98 GAllen98 force-pushed the add-watcher-to-restart-server-on-code-changes branch from 2f16ed5 to 0749e98 Compare February 18, 2025 14:31
Also added a flag to disable the watcher
@GAllen98 GAllen98 force-pushed the add-watcher-to-restart-server-on-code-changes branch from 0749e98 to 5e9f807 Compare February 18, 2025 14:34
Comment on lines +171 to +181
async function restartServer(
server: Server<typeof IncomingMessage, typeof ServerResponse>,
deployedUrl: string,
serverPort: number,
): Promise<Server<typeof IncomingMessage, typeof ServerResponse>> {
server.close();
const { spec } = await fetchAndValidateSpec(deployedUrl);
const newServer = await startUIServer(API_CONFIG, spec);
await open(`http://localhost:${serverPort}`);
return newServer;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the way to do it almost for sure, you need to hot reload the route which is serving the spec not restart the entire server (unless that doesn't work for some reason)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all that logic is inside startUIServer() so I don't see how I could do that in a straightforward way.
I could try and break everything down and restructure it for that to work, or even fetch the spec inside the GET /api/config route every time it gets called but I don't think it's worth it for either case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the open() call may not be necessary but I couldn't find a way to reload ui components so I just opened a new instance

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opening and closing the server is gonna be ultra slow and terrible devx, I think its worth tweaking whatever needs to be tweaked to fix this problem properly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants