static-web-apps-cli icon indicating copy to clipboard operation
static-web-apps-cli copied to clipboard

Hot reload staticwebapp.config.json changes when server is running

Open manekinekko opened this issue 4 years ago • 5 comments

Is your feature request related to a problem? Please describe. We need to support hot reloading the staticwebapp.config.json file whenever it got edited, without restarting the server.

Describe alternatives you've considered Currently, users need to kill the server and restart it so their changes get applied.

Additional context Currently, we read and cache the staticwebapp.config.json when starting the server: https://github.com/Azure/static-web-apps-cli/blob/722616015d16059d697428bd44f143ad72857b02/src/msha/server.ts#L146-L154

An easy implementation would be to move the call to await handleUserConfig(...) inside: https://github.com/Azure/static-web-apps-cli/blob/722616015d16059d697428bd44f143ad72857b02/src/msha/server.ts#L49-L51

manekinekko avatar Jul 30 '21 15:07 manekinekko

This is much needed feature, because it is really cumbersome for the user to restart the server every time he make changes in config file. Thanks for pointing out Wassim, will work on this.

sgollapudi77 avatar Aug 24 '21 07:08 sgollapudi77

@manekinekko for loading swa-config file we're using require here which is storing the files contents in a cache and is not reloading the contents of the file. Is there any workaround for this?

sgollapudi77 avatar Aug 24 '21 15:08 sgollapudi77

You can either clear the cached file before calling require() using such a helper function:

function clearCacheAndRequire(module: string) {
    delete require.cache[require.resolve(module)];
    return require(module);
}

Or, you can use fs.readFileSync() to always read the file from disk.

manekinekko avatar Aug 24 '21 19:08 manekinekko

@sgollapudi77 did you manage to finish work on this feature?

manekinekko avatar Apr 12 '22 15:04 manekinekko

No Wassim, I didn't get chance to work on this feature.

sgollapudi77 avatar Apr 20 '22 12:04 sgollapudi77