diff options
author | 2025-06-05 14:25:23 +0000 | |
---|---|---|
committer | 2025-06-05 14:25:23 +0000 | |
commit | e586d7d704d475afe3373a1de6ae20d504f79d6d (patch) | |
tree | 7e3fa24807cebd48a86bd40f866d792181191ee9 /packages/integrations/node/src/index.ts | |
download | astro-latest.tar.gz astro-latest.tar.zst astro-latest.zip |
Sync from a8e1c0a7402940e0fc5beef669522b315052df1blatest
Diffstat (limited to 'packages/integrations/node/src/index.ts')
-rw-r--r-- | packages/integrations/node/src/index.ts | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/packages/integrations/node/src/index.ts b/packages/integrations/node/src/index.ts new file mode 100644 index 000000000..26ffd2ad0 --- /dev/null +++ b/packages/integrations/node/src/index.ts @@ -0,0 +1,79 @@ +import { fileURLToPath } from 'node:url'; +import type { AstroAdapter, AstroIntegration } from 'astro'; +import { AstroError } from 'astro/errors'; +import type { Options, UserOptions } from './types.js'; + +export function getAdapter(options: Options): AstroAdapter { + return { + name: '@astrojs/node', + serverEntrypoint: '@astrojs/node/server.js', + previewEntrypoint: '@astrojs/node/preview.js', + exports: ['handler', 'startServer', 'options'], + args: options, + adapterFeatures: { + buildOutput: 'server', + edgeMiddleware: false, + }, + supportedAstroFeatures: { + hybridOutput: 'stable', + staticOutput: 'stable', + serverOutput: 'stable', + sharpImageService: 'stable', + i18nDomains: 'experimental', + envGetSecret: 'stable', + }, + }; +} + +export default function createIntegration(userOptions: UserOptions): AstroIntegration { + if (!userOptions?.mode) { + throw new AstroError(`Setting the 'mode' option is required.`); + } + + let _options: Options; + return { + name: '@astrojs/node', + hooks: { + 'astro:config:setup': async ({ updateConfig, config, logger }) => { + let session = config.session; + + if (!session?.driver) { + logger.info('Enabling sessions with filesystem storage'); + session = { + ...session, + driver: 'fs-lite', + options: { + base: fileURLToPath(new URL('sessions', config.cacheDir)), + }, + }; + } + + updateConfig({ + image: { + endpoint: { + route: config.image.endpoint.route ?? '_image', + entrypoint: config.image.endpoint.entrypoint ?? 'astro/assets/endpoint/node', + }, + }, + session, + vite: { + ssr: { + noExternal: ['@astrojs/node'], + }, + }, + }); + }, + 'astro:config:done': ({ setAdapter, config }) => { + _options = { + ...userOptions, + client: config.build.client?.toString(), + server: config.build.server?.toString(), + host: config.server.host, + port: config.server.port, + assets: config.build.assets, + }; + setAdapter(getAdapter(_options)); + }, + }, + }; +} |