UNPKG

@astrojs/node

Version:
77 lines (76 loc) 2.11 kB
import { fileURLToPath } from "node:url"; import { AstroError } from "astro/errors"; function getAdapter(options) { 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" } }; } function createIntegration(userOptions) { if (!userOptions?.mode) { throw new AstroError(`Setting the 'mode' option is required.`); } let _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)); } } }; } export { createIntegration as default, getAdapter };