#Cluster Node SSR astro app
4 messages · Page 1 of 1 (latest)
Hi @vapid valve. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Based on the provided knowledge sources:
1. Using Node Cluster API with Astro Node SSR (middleware mode):
The documentation does not explicitly mention support or examples for using the Node.js cluster API with Astro’s Node SSR adapter in middleware mode. However, since the middleware output is a standard Node.js handler (exported from ./dist/server/entry.mjs), in principle, you could use it within a custom Node.js server that utilizes the cluster API. You would need to handle clustering logic yourself and ensure each worker process serves requests using the Astro handler. There is no official guidance or example for this setup in the knowledge sources, so you may encounter edge cases or unsupported scenarios.
2. Using TypeScript for the cluster script:
The documentation does not provide information about writing your custom cluster script in TypeScript. Astro supports TypeScript for its own configuration and components, but running a custom server (like a cluster manager) in TypeScript would require you to transpile your TypeScript code to JavaScript before running it with Node.js. This is outside the scope of Astro’s documented features, but is generally possible in a Node.js environment if you set up your build tooling accordingly TypeScript Guide.
3. Configuring with astro.config.mjs:
You configure Astro to output middleware-compatible SSR code by setting the Node adapter in astro.config.mjs with mode: 'middleware':
import { defineConfig } from 'astro/config';
import node from '@astrojs/node';
export default defineConfig({
adapter: node({ mode: 'middleware' }),
});
This will output the handler at `./dist/server/entry.mjs`, which you can import and use in your custom server (including one using cluster) [Node Adapter Configuration](<https://docs.astro.build/en/guides/integrations-guide/node/#configuration>).
**4. Does this work in dev mode?**
No, the middleware output and custom server setup (including clustering) are for production builds. In development mode, Astro runs its own dev server and does not use your custom server or the middleware output. You must build your project (`astro build`) to generate the SSR middleware output for use with your own server [Node Adapter Usage](<https://docs.astro.build/en/guides/integrations-guide/node/#usage>).
---
**Summary:**
- You can use the Node SSR middleware output in a custom server, potentially with the cluster API, but this is not officially documented or supported.
- TypeScript can be used for your own scripts if you handle transpilation.
- Configure Astro with the Node adapter in middleware mode.
- This setup is for production only, not for dev mode.
If you need official support or examples for clustering, the knowledge sources do not provide them. Proceed with caution and test thoroughly.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------