Nuxt.js: Add HMR or automatic server restart for modified serverMiddleware scripts

Created on 28 Aug 2017  路  17Comments  路  Source: nuxt/nuxt.js

Hi

The use case is that I am developing some back-end APIs for my app. To do that I use serverMiddleware and leverage the express router to implement my APIs. The config looks like this:

nuxt.config.js

    serverMiddleware: [
        '~/api/index.js',
    ]

So, each time I make changes to and save /api/index.js, or any scripts it imports, I would like the server portion of the app to reload/restart and use the latest code, just like the scripts in pages and components folders do.

However, currently that is not the case. I have to manually restart NUXT each time I want to test my changes, which is quite slow.

This feature request is available on Nuxt.js community (#c1344)
enhancement feature-request

Most helpful comment

Hi @pi0. Is this feature integrated already?

All 17 comments

Hi @pbastowski . Your suggestion is awesome and indeed already planned. We need some special code for HMR middleware stack. The necessary injection part for renderer is already done (f933dd1f32f36b488230a03d500de4d8282e2f3f) but watchers and hot replacement logic for builder is remaining. Will keep this thread updated.

Thanks @pi0.

Paul

Hi @pi0. Is this change integrated in rc11?
I saw the v1.0.0-rc11 label on the commit and thought it might be available now, but it doesn't appear to be so.

Hey paul, and thanks for your interest. This feature still is not completed, but is on roadmap and will be coming soon :)

Thanks for your quick answer, Pooya :)

Hi @pi0. Is this feature integrated already?

Hi @pi0, why is this feature not finished yet? It sounds quite easy to implement.

Aren't you guys using API with nuxt?

@galvez has introduced the config for custom defined watch options, maybe he can answser this question.

@galvez How about add the serverMiddleware into default value of the new watcher ?

@clarkdo @manniL k, add this to my queue for next PRs. should get to it soon.

@bf Thank you for the reminding, @pi0 is busy with his personal works recently, sorry for that he can't be active for now, but we should all appreciate his extraordinary work for open source very much, I believe he and @Atinux are the most valuable person for this project.

Nuxt is an open source project, so everyone here is using their private time to contribute, I am very grateful to everyone for their contributions, including code contributions, issues closing and even opening issues, I have you are having same feeling 馃樃.

Of course, if you have any great idea, we all very welcome any pr to improve this project.

Thanks for your immediate response. I appreciate the great work done by all of you in this project.

Just started using nuxt today and I already feel the productivity boost after working in a hapi/react/flux/react-router setup for some years.

Also, the docs for build.watch seem to be wrong. The tilde ~ in watch: ["~/api/index.js"] is not working. I need to use watch: [__dirname + '/api/index.js'].

@bf thanks for letting us know, I'll look into it.

@pbastowski should be in nuxt-edge soon :)

This feature-request has been implemented by @galvez, @clarkdo.

See the PR

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Should be fully possible with #6881 without need to watch :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pehbehbeh picture pehbehbeh  路  3Comments

mikekidder picture mikekidder  路  3Comments

danieloprado picture danieloprado  路  3Comments

uptownhr picture uptownhr  路  3Comments

nassimbenkirane picture nassimbenkirane  路  3Comments