#Hooks with @astro/node standalone
4 messages · Page 1 of 1 (latest)
Hi @limber dagger. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
The astro:server:setup hook is indeed used in the development mode of Astro, as it is called just after the Vite server is created in “dev” mode, but before the listen() event is fired. This hook is used to update Vite server options and middleware source (https://docs.astro.build/en/reference/integrations-reference#astroserversetup).
However, when you run astro build and use the standalone mode of the Node.js adapter, the behavior might be different. The standalone mode builds a server that automatically starts when the entry module is run, allowing you to more easily deploy your build to a host without any additional code source (https://astro.build/blog/astro-150#standalone-mode-in-nodejs-adapter).
The standalone mode of the Node.js adapter is designed to start your production server without needing to write any server JavaScript logic yourself source (https://astro.build/blog/astro-150#standalone-mode-in-nodejs-adapter). This might be why your custom middleware is not being called in this mode.
If you want to use your custom middleware in the production environment, you might want to consider using the middleware mode of the Node.js adapter. This mode allows the built output to be used as middleware for another Node.js server, like Express.js or Fastify source (https://docs.astro.build/en/guides/integrations-guide/node#configuration).
Here is an example of how to set the mode option to 'middleware' in your Astro config:
import { defineConfig } from 'astro/config';
import node from '@astrojs/node';
export default defineConfig({
output: 'server',
adapter: node({ mode: 'middleware', }),
});
**source** (<https://docs.astro.build/en/guides/integrations-guide/node#configuration>)
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------