@cribops/astro
v0.1.1
Published
Deploy Astro sites to AWS with CribOps - S3, CloudFront, Lambda SSR, and Hive caching
Downloads
16
Maintainers
Readme
@cribops/astro
Deploy Astro sites to AWS with CribOps — S3, CloudFront, Lambda SSR, and Hive caching.
Early Development — This adapter is under active development. API may change. Not yet recommended for production use.
Features
- Three deployment tiers: Starter (SSG), Pro (Hybrid), Scale (Full SSR)
- AWS-native: S3 + CloudFront CDN with Lambda@Edge SSR
- Hive caching: Sub-millisecond Redis-compatible caching
- WordPress integration: Headless CMS with intelligent cache invalidation
- Streaming SSR: Progressive HTML rendering for faster TTFB
- Multi-region: Deploy to multiple AWS regions for global performance
Installation
npm install @cribops/astroQuick Start
// astro.config.mjs
import { defineConfig } from 'astro/config';
import cribops from '@cribops/astro';
export default defineConfig({
output: 'hybrid', // or 'server' for full SSR
adapter: cribops({
tier: 'pro', // 'starter' | 'pro' | 'scale'
region: 'us-east-1',
}),
});Deployment Tiers
Starter (Static)
Pure static site generation — fastest and cheapest.
adapter: cribops({
tier: 'starter',
})- ✅ S3 + CloudFront CDN
- ✅ Custom domains with SSL
- ✅ GitHub auto-deploy
- ❌ No SSR routes
Pro (Hybrid)
Static pages with on-demand SSR for dynamic routes.
adapter: cribops({
tier: 'pro',
hive: {
enabled: true,
defaultTTL: 3600,
},
})- ✅ Everything in Starter
- ✅ Lambda SSR for dynamic routes
- ✅ Hive caching
- ✅ Session management
Scale (Full SSR)
All routes rendered on-demand with full infrastructure.
adapter: cribops({
tier: 'scale',
regions: ['us-east-1', 'eu-west-1'],
lambda: {
memory: 2048,
streaming: true,
},
})- ✅ Everything in Pro
- ✅ Multi-region deployment
- ✅ Aurora database access
- ✅ Streaming SSR
Using Hive Cache
Hive is CribOps's Redis-compatible caching layer with sub-millisecond latency.
Basic Usage
---
// src/pages/blog/[slug].astro
import { hive } from '@cribops/astro/hive';
export const prerender = false;
const { slug } = Astro.params;
// Get or set cached content
const post = await hive.getOrSet(
`post:${slug}`,
async () => {
const res = await fetch(`https://api.example.com/posts/${slug}`);
return res.json();
},
{ ttl: 3600, tags: ['posts', `post:${slug}`] }
);
---
<article>
<h1>{post.title}</h1>
<div set:html={post.content} />
</article>Cache Invalidation
import { hive } from '@cribops/astro/hive';
// Invalidate by tag
await hive.invalidateTag('posts');
// Invalidate by pattern
await hive.invalidatePattern('post:*');
// Publish invalidation event
await hive.publish('cache:invalidate', { pattern: 'post:*' });Middleware
Cache Middleware
Automatically cache SSR pages in Hive:
// src/middleware.ts
import { sequence } from 'astro:middleware';
import { createCacheMiddleware } from '@cribops/astro/middleware';
const cache = createCacheMiddleware({
defaultTTL: 3600,
excludePatterns: ['/api/*', '/admin/*'],
staleWhileRevalidate: true,
});
export const onRequest = sequence(cache);Control caching per-page with headers:
---
// Cache this page for 1 hour
Astro.response.headers.set('X-Cache-TTL', '3600');
---Session Middleware
Manage user sessions via Hive:
// src/middleware.ts
import { sequence } from 'astro:middleware';
import { createSessionMiddleware } from '@cribops/astro/middleware';
const session = createSessionMiddleware({
cookieName: 'session',
ttl: 86400, // 24 hours
});
export const onRequest = sequence(session);Access sessions in pages:
---
// Get session data
const user = Astro.locals.session?.get('user');
// Set session data
Astro.locals.session?.set('cart', { items: [] });
---WordPress Integration
Use Astro as a headless frontend for WordPress:
// astro.config.mjs
adapter: cribops({
tier: 'pro',
wordpress: {
url: 'https://wp.mysite.com',
cache: true,
cacheTTL: 300,
},
})---
// src/pages/blog/[slug].astro
import { hive } from '@cribops/astro/hive';
const { slug } = Astro.params;
const wpUrl = import.meta.env.WORDPRESS_URL;
const post = await hive.getOrSet(
`wp:post:${slug}`,
async () => {
const res = await fetch(`${wpUrl}/wp-json/wp/v2/posts?slug=${slug}`);
const posts = await res.json();
return posts[0];
},
{ ttl: 300, tags: ['wordpress', 'wp:posts'] }
);
---Configuration Reference
interface CribopsAdapterOptions {
// Deployment tier
tier?: 'starter' | 'pro' | 'scale';
// AWS region
region?: string;
// Multi-region deployment (scale tier only)
regions?: string[];
// Lambda configuration
lambda?: {
memory?: number; // MB (128-10240)
timeout?: number; // seconds (1-900)
architecture?: 'arm64' | 'x86_64';
streaming?: boolean;
};
// Hive cache configuration
hive?: {
enabled?: boolean;
host?: string;
port?: number;
database?: number;
defaultTTL?: number;
};
// WordPress integration
wordpress?: {
url?: string;
cache?: boolean;
cacheTTL?: number;
};
}Environment Variables
| Variable | Description |
|----------|-------------|
| HIVE_HOST | Hive server hostname |
| HIVE_PORT | Hive server port (default: 6379) |
| HIVE_DATABASE | Hive database number |
| HIVE_PASSWORD | Hive authentication password |
| CRIBOPS_SITE_ID | Site ID for key prefixing |
| WORDPRESS_URL | WordPress REST API URL |
Deployment
Via CribOps Platform
- Connect your GitHub repository in the CribOps dashboard
- Select your deployment tier
- Push to deploy
Manual Deployment
# Build your site
npm run build
# The build outputs:
# - dist/client/ → Upload to S3
# - dist/server/ → Deploy to Lambda
# - dist/cribops-manifest.json → Provisioning configComparison with Cloudflare
| Feature | Cloudflare | CribOps | |---------|------------|---------| | KV Store | Workers KV (60s consistency) | Hive (<1ms, strong consistency) | | Database | D1 (SQLite) | Aurora (PostgreSQL/MySQL) | | Storage | R2 | S3 | | Edge Compute | Workers | Lambda@Edge | | Sessions | KV-based | Hive (Redis-compatible) |
License
MIT © CloudBedrock
