Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 102 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,104 @@
# strapi-launchpad

[Vercel's LaunchPad: Next.js × Strapi Starter](https://github.com/strapi/LaunchPad) on
**Cloudflare Workers**, deployed by [Orun](https://github.com/sourceplane/orun) to stage
and prod on every merge, and then packaged as an Orun baseline.

This commit is the repository's frame: `intent.yaml` (with the placeholder
workspace `ws_CHANGE_ME`, so CI plans nothing until it is linked), the Orun
CI workflow, the shared TypeScript and ESLint configuration, and the spec
index. The work is tracked as an epic under [`specs/epics`](specs/epics/README.md).
The Next.js front end of [LaunchPad](https://github.com/strapi/LaunchPad)
(the template Vercel lists as LaunchPad: Next.js × Strapi Starter) — a
marketing site whose home page is built from Strapi's dynamic zones, with
pricing, FAQ and contact pages, a blog and a product catalogue, in English
and French, every Strapi read a `"use cache"` entry, and draft mode for
Strapi's preview — running on **Cloudflare Workers + Static Assets** through
[`@opennextjs/cloudflare`](https://opennext.js.org/cloudflare), with the
Next.js data cache in an **R2 bucket** provisioned by Terraform through
[Orun](https://github.com/sourceplane/orun) and the tag cache and revalidation
queue in **Durable Objects** the Worker itself exports, deployed by
[Orun](https://github.com/sourceplane/orun) to stage and prod on every merge.
Packaging it as an Orun baseline is the next milestone (SL2).

The Strapi server is not part of it: running Strapi needs a long-lived Node
server (a container), which this baseline does not carry. A fresh build needs
no Strapi project: until its owner connects one — a Strapi Cloud project
running LaunchPad's `strapi/` app — the site renders the template's own seed
as sample content, under a bar that says how to connect one, never a 500. The
owner connects a project by setting its URL as an Orun secret and
redeploying. See [`specs/epics/strapi-launchpad`](specs/epics/strapi-launchpad/README.md)
for the design, the milestones and the as-built status.

## What is here (the product)

| Surface | Where |
|---|---|
| The pages: `/[locale]`, `/[locale]/[slug]`, `/[locale]/blog/…`, `/[locale]/products/…`, sign-up; `/api/preview`, `/api/exit-preview`, `/api/health` | `apps/web/app` |
| The site's name and source link | `apps/web/lib/site.ts` (`SITE_NAME`, `SOURCE_URL`) |
| Strapi's cached reads; whether a project is connected | `apps/web/lib/strapi/client.ts` |
| The sample content — the template's seed, as a Strapi that imported it returns it — and its images | `apps/web/sample/strapi`, `apps/web/public/uploads`, `apps/web/lib/strapi/sample.ts` |
| Workers build, cache bindings and deploy contract | `apps/web/next.config.ts`, `open-next.config.ts`, `wrangler.template.jsonc` + `wiring.fixture.json` (→ the committed `wrangler.jsonc`), `component.yaml` |
| The R2 bucket (stage, prod) | `infra/terraform/cloudflare-r2` |
| The wrangler renderer | `tooling/wire` |
| Tests | `tests/web` (the port's seams) |

## Getting started

```bash
pnpm install
pnpm run wire:fixture # render apps/web/wrangler.jsonc from the offline fixture
pnpm typecheck
pnpm lint
pnpm test
pnpm build # next build + opennextjs-cloudflare build → apps/web/.open-next
```

```bash
pnpm --filter @app/web dev # http://localhost:3000, Next's dev server
pnpm --filter @app/web preview # wrangler dev over the built Worker, a local R2 bucket and local Durable Objects
```

With no `STRAPI_URL` both serve the sample content. To run against a project,
put its URL in `apps/web/.env.local` (from `apps/web/.env.example`). Offline,
the e2e's stand-in Strapi answers the site's reads from the same seed:
`python3 testing/lib/fake-strapi.py --sample apps/web/sample/strapi --uploads apps/web/public/uploads --port 4010`.

## How it maps to Vercel

| Vercel | Here |
|---|---|
| Next.js hosting (SSR, route handlers, the proxy, draft mode) | One Cloudflare Worker (`.open-next/worker.js`) + Static Assets (`ASSETS`) |
| Cache Components with `"use cache"`, `cacheLife` and `cacheTag` | `"use cache"`, its profile and its tags kept through `experimental.useCache`; every page renders per request from those cached reads |
| Data Cache entries | The R2 bucket bound as `NEXT_INC_CACHE_R2_BUCKET` |
| `revalidateTag` | A sharded Durable Object tag cache (`NEXT_TAG_CACHE_DO_SHARDED`) consulted on every cache read |
| Stale-while-revalidate | A Durable Object queue (`NEXT_CACHE_DO_QUEUE`) that re-renders stale entries through the Worker's `WORKER_SELF_REFERENCE` binding |
| Image Optimization (`sharp`) | Off (`images.unoptimized`): Strapi's media are served as uploaded |
| `NEXT_PUBLIC_API_URL` | The Orun secret `STRAPI_URL` (optional build env) — and, unset, the template's own seed as sample content instead of a failed build |
| `PREVIEW_SECRET` | A Worker secret |
| The Strapi server (`strapi/`) | Not carried: Strapi Cloud (or the owner's own Strapi), connected after the build |
| Deploy on push | Orun applies the bucket and deploys `<repo>-web-{stage,prod}` on merge to `main` (`apps/web/component.yaml`) |
| "Deploy with Vercel" (clone the template) | `orun new --blueprint repo-blueprint.yaml` — a new repository, branded, deployed |

Cache Components are off: `@opennextjs/cloudflare` 1.20 cannot run Next 16's
Cache Components on workerd yet (a Cache Components page answers 500 and then
hangs — opennextjs-cloudflare#1450), so the site keeps upstream's `"use cache"`
reads through `experimental.useCache` and renders every page at request time.
The epic's [IMPLEMENTATION-STATUS](specs/epics/strapi-launchpad/IMPLEMENTATION-STATUS.md)
has the evidence.

## How the bucket reaches the Worker

```
infra/terraform/cloudflare-r2 ──apply (r2-data token)──► orun secret WIRING_CLOUDFLARE_R2 (stage, prod)
│ (each deploy resolves it as it starts;
│ a missing one fails the lane)
▼
apps/web dependsOn cloudflare-r2 (enforced on main) · secretEnv WIRING_CLOUDFLARE_R2_<ENV>
build: tooling/wire/live.mjs → wrangler.jsonc with the environment's bucket name
(dev, verify-only, renders the fixture) → next build → opennextjs-cloudflare
deploy: workers-deploy token → <repo>-web-<env>, its Durable Objects migrated on first deploy
```

`wrangler.jsonc` is committed as the fixture render of
`wrangler.template.jsonc`, because the deploy lane's `verify-app-structure`
step checks the config exists before it builds; `testing/e2e.test.sh` fails
if the two disagree.

## CI

| Workflow | What it runs | Ships to a product |
|---|---|---|
| `ci.yml` | the Orun pipeline, and the only workflow a product carries: `orun plan --changed`, then one job per lane. A pull request runs the verify lanes (the R2 root planned for stage and prod, the site built and dry-deployed per environment; they neither lint nor run the tests, which `baseline.yml`'s e2e tier runs before every tag), except the bootstrap's own landings (`orun/BASE-*`), where `plan` alone runs and nothing waits for it (the landing checked its commit in the box); a merge applies the R2 bucket, then deploys stage → prod. It plans nothing while `intent.yaml` names the placeholder workspace `ws_CHANGE_ME`, as this repository does. A manual run (Orunbase's Deploy button, or Run workflow on `main`) plans the environment and components it names under the push-to-main trigger, so they deploy as a merge deploys them | yes |
3 changes: 3 additions & 0 deletions apps/web/.dev.vars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Worker secrets for `pnpm --filter @app/web preview` (wrangler dev) — copy to
# .dev.vars. Deployed Workers take theirs from `wrangler secret put`.
PREVIEW_SECRET=
15 changes: 15 additions & 0 deletions apps/web/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Local settings for `pnpm --filter @app/web dev` — copy to .env.local.
# Deployed environments take theirs from Orun secrets (component.yaml); never
# commit a .env.local.

# Your Strapi project's public URL (e.g. https://<project>.strapiapp.com, or
# http://localhost:1337 for a local Strapi running LaunchPad's strapi/ app).
# Empty: the site renders its bundled sample content.
STRAPI_URL=

# Strapi's preview secret: /api/preview?secret=… turns on draft mode. Empty:
# preview is refused.
PREVIEW_SECRET=

# The origin the Open Graph images resolve against.
NEXT_PUBLIC_SITE_URL=http://localhost:3000
34 changes: 34 additions & 0 deletions apps/web/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Licence

The site is the Next.js front end of [strapi/LaunchPad](https://github.com/strapi/LaunchPad)
(`next/`), and its sample content and images are that repository's seed
(`strapi/data/export_20250116105447.tar.gz`). LaunchPad is published under the
MIT License: its `next/README.md` says so and its `strapi/package.json`
declares `"license": "MIT"`. The repository carries no LICENSE file of its
own, so the text below is the standard MIT License, with LaunchPad's authors
— Strapi, the company the template's footer credits, and its contributors —
as the copyright holders.

---

MIT License

Copyright (c) 2024 Strapi, Inc. and the LaunchPad contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
16 changes: 16 additions & 0 deletions apps/web/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# apps/web

The site: LaunchPad's Next.js front end ([strapi/LaunchPad](https://github.com/strapi/LaunchPad)
`next/`, MIT — `LICENSE.md`) on Cloudflare Workers + Static Assets through
`@opennextjs/cloudflare`. The repository's README has how to run, connect
Strapi and deploy it; `docs/` describes the component (generated from what it
declares).

| | |
|---|---|
| The pages and route handlers | `app/` |
| The blocks Strapi's dynamic zones render, the navbar, the footer | `components/` |
| Strapi's cached reads, and the switch to the sample | `lib/strapi/` |
| The sample content and its images | `sample/strapi/`, `public/uploads/` |
| The site's name | `lib/site.ts` |
| The build on Workers | `next.config.ts`, `open-next.config.ts`, `wrangler.template.jsonc` |
22 changes: 22 additions & 0 deletions apps/web/app/[locale]/(marketing)/ClientSlugHandler.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use client';

import { useRouter } from 'next/navigation';
import { useEffect } from 'react';

import { useSlugContext } from '@/app/context/SlugContext';

export default function ClientSlugHandler({
localizedSlugs,
}: {
localizedSlugs: Record<string, string>;
}) {
const { dispatch } = useSlugContext();

useEffect(() => {
if (localizedSlugs) {
dispatch({ type: 'SET_SLUGS', payload: localizedSlugs });
}
}, [localizedSlugs, dispatch]);

return null; // This component only handles the state and doesn't render anything.
}
43 changes: 43 additions & 0 deletions apps/web/app/[locale]/(marketing)/[slug]/loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Container } from '@/components/container';
import {
PageHeroSkeleton,
SkeletonBlock,
} from '@/components/skeletons/page-skeleton';

// The `[slug]` route renders dynamic-zone pages (e.g. /pricing). This fallback
// mirrors the real Pricing layout: a centered hero followed by a 4-column grid
// of plan cards, so the skeleton lines up with the content that replaces it.
export default function Loading() {
return (
<div className="relative overflow-hidden w-full">
<Container>
<PageHeroSkeleton />
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 max-w-7xl mx-auto gap-4 py-20 lg:items-start">
{[...Array(4)].map((_, index) => (
<PlanCardSkeleton key={index} />
))}
</div>
</Container>
</div>
);
}

function PlanCardSkeleton() {
return (
<div className="p-4 rounded-3xl bg-neutral-900 border-2 border-neutral-800">
<div className="p-4 bg-neutral-800 rounded-2xl">
<SkeletonBlock className="h-5 w-28 bg-neutral-700" />
<SkeletonBlock className="mt-8 h-10 w-32 bg-neutral-700" />
<SkeletonBlock className="mt-10 mb-4 h-10 w-full bg-neutral-700" />
</div>
<div className="mt-1 p-4 space-y-6">
{[...Array(4)].map((_, index) => (
<div key={index} className="flex items-center gap-2">
<SkeletonBlock className="h-4 w-4 rounded-full bg-neutral-700" />
<SkeletonBlock className="h-4 flex-1 bg-neutral-700" />
</div>
))}
</div>
</div>
);
}
58 changes: 58 additions & 0 deletions apps/web/app/[locale]/(marketing)/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Metadata } from 'next';
import { notFound } from 'next/navigation';

import ClientSlugHandler from '../ClientSlugHandler';
import PageContent from '@/lib/shared/PageContent';
import { generateMetadataObject } from '@/lib/shared/metadata';
import { fetchCollectionType } from '@/lib/strapi';
import type { LocaleSlugParamsProps } from '@/types/types';

export async function generateMetadata({
params,
}: LocaleSlugParamsProps): Promise<Metadata> {
const { slug, locale } = await params;
const [pageData] = await fetchCollectionType('pages', {
filters: {
slug: {
$eq: slug,
},
locale: locale,
},
});

// A slug with no page is a 404 (upstream read `.seo` of undefined).
if (!pageData) notFound();

const seo = pageData.seo;
const metadata = generateMetadataObject(seo);
return metadata;
}

export default async function Page({ params }: LocaleSlugParamsProps) {
const { slug, locale } = await params;
const [pageData] = await fetchCollectionType('pages', {
filters: {
slug: {
$eq: slug,
},
locale: locale,
},
});

if (!pageData) notFound();

const localizedSlugs = pageData.localizations?.reduce(
(acc: Record<string, string>, localization: any) => {
acc[localization.locale] = localization.slug;
return acc;
},
{ [locale]: slug }
);

return (
<>
<ClientSlugHandler localizedSlugs={localizedSlugs} />
<PageContent pageData={pageData} />
</>
);
}
33 changes: 33 additions & 0 deletions apps/web/app/[locale]/(marketing)/blog/[slug]/loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Container } from '@/components/container';
import { SkeletonBlock } from '@/components/skeletons/page-skeleton';

export default function Loading() {
return (
<div className="relative overflow-hidden w-full">
<Container className="pt-40 pb-20">
<article className="max-w-4xl mx-auto">
{/* Title */}
<SkeletonBlock className="h-12 w-3/4 mb-4" />

{/* Meta info */}
<div className="flex gap-4 mb-8">
<SkeletonBlock className="h-4 w-24" />
<SkeletonBlock className="h-4 w-32" />
</div>

{/* Featured image */}
<SkeletonBlock className="aspect-video w-full mb-8" />

{/* Content */}
<div className="space-y-4">
{['w-full', 'w-11/12', 'w-10/12', 'w-full', 'w-9/12', 'w-11/12'].map(
(width, index) => (
<SkeletonBlock key={index} className={`h-4 ${width}`} />
)
)}
</div>
</article>
</Container>
</div>
);
}
38 changes: 38 additions & 0 deletions apps/web/app/[locale]/(marketing)/blog/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import ClientSlugHandler from '../../ClientSlugHandler';
import { ArticleContent } from '@/components/article-content';
import { BlogLayout } from '@/components/blog-layout';
import { fetchCollectionType } from '@/lib/strapi';
import type { Article, LocaleSlugParamsProps } from '@/types/types';

export default async function SingleArticlePage({
params,
}: LocaleSlugParamsProps) {
const { slug, locale } = await params;
const [article] = await fetchCollectionType<Article[]>('articles', {
filters: {
slug: {
$eq: slug,
},
},
locale,
});

if (!article) {
return <div>Blog not found</div>;
}

const localizedSlugs = article.localizations.reduce(
(acc: Record<string, string>, localization: any) => {
acc[localization.locale] = localization.slug;
return acc;
},
{ [locale]: slug }
);

return (
<BlogLayout article={article} locale={locale}>
<ClientSlugHandler localizedSlugs={localizedSlugs} />
<ArticleContent content={article.content} />
</BlogLayout>
);
}
Loading
Loading