mirror of
https://github.com/withastro/astro.git
synced 2025-03-24 23:21:57 -05:00
actions: Throw error on missing server output (#11028)
* feat: throw error on missing server output * chore: changeset * refactor: use isServerLikeOutput * feat: add errors-data on actions build output * chore: add jsdoc
This commit is contained in:
parent
ad9227c7d1
commit
771d1f7654
3 changed files with 29 additions and 1 deletions
5
.changeset/many-news-rescue.md
Normal file
5
.changeset/many-news-rescue.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"astro": patch
|
||||
---
|
||||
|
||||
Throw on missing server output when using Astro Actions.
|
|
@ -1,14 +1,22 @@
|
|||
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
||||
import type { Plugin as VitePlugin } from 'vite';
|
||||
import type { AstroIntegration } from '../@types/astro.js';
|
||||
import { viteID } from '../core/util.js';
|
||||
import { viteID, isServerLikeOutput } from '../core/util.js';
|
||||
import { ACTIONS_TYPES_FILE, RESOLVED_VIRTUAL_MODULE_ID, VIRTUAL_MODULE_ID } from './consts.js';
|
||||
import { AstroError } from '../core/errors/errors.js';
|
||||
import { ActionsWithoutServerOutputError } from '../core/errors/errors-data.js';
|
||||
|
||||
export default function astroActions(): AstroIntegration {
|
||||
return {
|
||||
name: VIRTUAL_MODULE_ID,
|
||||
hooks: {
|
||||
async 'astro:config:setup'(params) {
|
||||
if (!isServerLikeOutput(params.config)) {
|
||||
const error = new AstroError(ActionsWithoutServerOutputError);
|
||||
error.stack = undefined;
|
||||
throw error;
|
||||
}
|
||||
|
||||
const stringifiedActionsImport = JSON.stringify(
|
||||
viteID(new URL('./actions', params.config.srcDir))
|
||||
);
|
||||
|
|
|
@ -1493,6 +1493,21 @@ export const DuplicateContentEntrySlugError = {
|
|||
},
|
||||
} satisfies ErrorData;
|
||||
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
* - [On-demand rendering](https://docs.astro.build/en/basics/rendering-modes/#on-demand-rendered)
|
||||
* @description
|
||||
* Your project must have a server output to create backend functions with Actions.
|
||||
*/
|
||||
export const ActionsWithoutServerOutputError = {
|
||||
name: 'ActionsWithoutServerOutputError',
|
||||
title: 'Actions must be used with server output.',
|
||||
message:
|
||||
'Actions enabled without setting a server build output. A server is required to create callable backend functions. To deploy routes to a server, add a server adapter to your astro config.',
|
||||
hint: 'Learn about on-demand rendering: https://docs.astro.build/en/basics/rendering-modes/#on-demand-rendered',
|
||||
} satisfies ErrorData;
|
||||
|
||||
/**
|
||||
* @docs
|
||||
* @see
|
||||
|
|
Loading…
Add table
Reference in a new issue