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

Hitting /restart endpoint does not restart with new plugins/routes. #9

Open
2 tasks done
ivanjeremic opened this issue Mar 12, 2022 · 2 comments
Open
2 tasks done
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers

Comments

@ivanjeremic
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

It says I can add dynamically routes and plugins without loosing request but something is not working for me.
I also use autoload so I started this server and while the server is running I added a new route in one of my plugins, then I hit the endpoint /refresh (which is also part of the official example) to refresh the app without downtime and get the new route working but hitting /newroute does not work, all I get is a 404 with "Route GET:xx not found" but after a shutting down the server and starting again the new route works, so maybe I'm missing something here any idea?

import { start } from '@fastify/restartable'
import autoLoad from "fastify-autoload";

async function myApp (app, opts) {
   //register autload /plugins
   await app.register(autoLoad, {
     dir: join(__dirname, "plugins"),
     maxDepth: 1,
   });

  app.get('/restart', async (req, reply) => {
    await app.restart()
    return { status: 'ok' }
  })
}

const { stop, restart, listen, inject } = await start({
  protocol: 'http', // or 'https'
  // key: ...,
  // cert: ...,
  // add all other options that you would pass to fastify
  host: '127.0.0.1',
  port: 3000,
  app: myApp
})

const { address, port } = await listen()

console.log('server listening on', address, port)
@mcollina
Copy link
Member

I can see why the readme could create confusion, but this module does not reload any code from disk. This module is useful if you are defining routes from a database and/or a config file.

If you want to hot-reload code, you would need to implement that yourself as for now. I'm currently exploring how to implement that feature with https://github.com/mcollina/fastify-isolate.

@ivanjeremic
Copy link
Author

I can see why the readme could create confusion, but this module does not reload any code from disk. This module is useful if you are defining routes from a database and/or a config file.

If you want to hot-reload code, you would need to implement that yourself as for now. I'm currently exploring how to implement that feature with https://github.com/mcollina/fastify-isolate.

Ok I understand, yes it was confusing at first to me looking at the readme. However hope to see that working soon because reloading from disk without loosing requests would be very powerful.

@mcollina mcollina added documentation Improvements or additions to documentation good first issue Good for newcomers labels Mar 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants