Astro 1.5.0

Автор
Matthew Phillips

Вышел Astro 1.5.0:

Обновление: npm install astro@latest.

Adapter support for astro preview

Поддержка astro preview в адаптерах через новую опцию интеграции, начиная с @astrojs/node. С @astrojs/node preview SSR-приложения:

npm run preview

Adapter API

Обновим остальные first-party адаптеры со временем. Opt-in через previewEntrypoint в setAdapter в хуке astro:config:done. Код Node.js adapter:

export default function() {
return {
name: '@astrojs/node',
hooks: {
'astro:config:done': ({ setAdapter, config }) => {
setAdapter({
name: '@astrojs/node',
serverEntrypoint: '@astrojs/node/server.js',
previewEntrypoint: '@astrojs/node/preview.js',
exports: ['handler'],
});
// more here
}
}
};
}

Standalone mode in Node.js adapter

В @astrojs/node — standalone mode. Production server без собственной серверной логики:

node ./dist/server/entry.mjs

Включение: mode: 'standalone' в конфиге Astro:

import { defineConfig } from "astro/config"
import nodejs from "@astrojs/node"
export default defineConfig({
output: "server",
adapter: nodejs({
mode: "standalone",
}),
})

См. документацию @astrojs/node.

Собственный HTTP framework вроде Express — mode: 'middleware' (как раньше):

import { defineConfig } from "astro/config"
import nodejs from "@astrojs/node"
export default defineConfig({
output: "server",
adapter: nodejs({
mode: "middleware",
}),
})

HMR for Tailwind and TypeScript config

HMR важен с начала проекта. Недавно изменения astro.config.mjs перезапускали сервер. Сегодня расширяем HMR на другие конфиги.

Изменения tsconfig.json (например, alias) — HMR update.

Изменения Tailwind — тоже. Редактируйте tailwind.config.(js|cjs|mjs) без перезапуска dev server.

Продолжаем фокус на HMR и dev experience.

API Endpoint improvements

В API routes доступны site, generator, url, clientAddress, props, redirect в APIContext — первый параметр API route. APIContext ближе к глобальному Astro в .astro страницах.

Пример clientAddress (IP пользователя) для выборочного доступа:

export function post({ clientAddress, redirect }) {
if (!allowList.has(clientAddress)) {
return redirect("/not-allowed")
}
}

См. документацию.

Astro.redirect status code

В 1.5 можно передать status code в Astro.redirect. По умолчанию 302, второй аргумент — другой код:

/src/pages/old-post.astro

---
// This page was moved, redirect the user to the new permanent page.
return Astro.redirect("/posts/new-post-name", 301)
---

Много исправлений. Спасибо участникам релиза. См. release notes.