server

Implements Astro API endpoints with validation, auth gating, env checks, and caching.

Updated Sep 6, 2026
One-click install
npx skills add https://github.com/malikkotb/shellpluscore --skill server-malikkotb
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: server
Source: https://github.com/malikkotb/shellpluscore/tree/main/.agents/skills/server
Command: npx skills add https://github.com/malikkotb/shellpluscore --skill server-malikkotb

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Building backend endpoints in an Astro project often leads to inconsistent response shapes, missing input validation, leaked secrets, and unclear auth rules. This Skill enforces a single set of server-side conventions so every endpoint in src/pages/api/ behaves predictably and securely. ## Core Features & Use Cases - Standardized endpoint structure: Endpoints export prerender = false and a typed APIRoute, return { ok } JSON via a local json() helper, and use consistent status codes (200, 400, 401, 404, 500, 502). - Auth and spam protection: Studio-triggered endpoints (AI generation, screenshots) are gated with isApiAuthorized, while public endpoints like the contact form rely on Zod validation plus honeypot and timing checks. - Env, caching, and side effects: Secrets come from src/lib/env.ts and never reach the client, cacheable GET endpoints declare TTL and tags via context.cache, and best-effort side effects like Resend email never fail the main request. - Use Case: When adding a new /api/newsletter-signup endpoint, apply this Skill to get correct file placement, body validation, env checks, and JSON error responses without reinventing the pattern. ## Quick Start Ask the AI to add a new API endpoint under src/pages/api/ following the server conventions, for example a POST endpoint that validates a request body and returns a JSON ok response.

Frequently Asked Questions about server

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create an API endpoint in Astro with file-based routing?

Create a file under src/pages/api/ and export prerender = false plus a typed APIRoute handler such as GET or POST. The file path maps to the URL, so src/pages/api/contact-form.ts serves /api/contact-form, and rest params like [...uri].ts work as usual.

How do I protect Astro API endpoints from unauthorized callers?

Gate Studio-triggered endpoints with isApiAuthorized(request) from src/features/api/auth, which checks origin and referer, and return unauthorizedResponse() on failure. Public endpoints like contact forms skip origin gating and instead use Zod validation plus honeypot and timing spam checks.

How should Astro endpoints read environment variables and secrets?

Read env from src/lib/env.ts, which re-exports astro:env, so secrets stay server-only and never reach the client. Check required values at the point of use and return a 500 response if configuration is missing.

Can Astro API endpoints be cached, and how is cache invalidated?

Cacheable GET endpoints declare TTL and tags via context.cache.set using CACHE_TTL and tags from src/lib/cache.ts; write endpoints never cache. The /api/revalidate webhook invalidates tags, and /api/cache-purge empties the whole route cache with bearer authentication.

What should an endpoint do when a side effect like sending email fails?

Treat side effects like Resend email as best-effort: complete the primary task first, then attempt the side effect. Report partial success in the response rather than failing the whole request, and log the failure server-side.