Skip to content

Commit 2bf58b6

Browse files
authored
examples: add example on Astro + Payload Local API (#10174)
Adds example on using the Local API (both fetching data and modifying data) with Astro (vanilla JS) https://github.com/user-attachments/assets/bf2dee99-2ad7-43f5-b809-1cf626051720 This is achieved through the monorepo: ``` website/ payload/ ```
1 parent 2ce3829 commit 2bf58b6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+10422
-0
lines changed

examples/astro/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.pnpm-debug.log*
2+
node_modules/
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"recommendations": ["astro-build.astro-vscode"],
3+
"unwantedRecommendations": []
4+
}

examples/astro/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "remix-payload-monorepo",
3+
"version": "1.0.0",
4+
"description": "",
5+
"keywords": [],
6+
"license": "ISC",
7+
"author": "",
8+
"main": "index.js",
9+
"scripts": {
10+
"dev:payload": "cd payload && pnpm dev",
11+
"dev:website": "cd website && pnpm dev",
12+
"test": "echo \"Error: no test specified\" && exit 1"
13+
}
14+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
DATABASE_URI=mongodb://127.0.0.1/payload-template-blank-3-0
2+
PAYLOAD_SECRET=YOUR_SECRET_HERE
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all",
4+
"printWidth": 100,
5+
"semi": false
6+
}

examples/astro/payload/Dockerfile

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# From https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile
2+
3+
FROM node:18-alpine AS base
4+
5+
# Install dependencies only when needed
6+
FROM base AS deps
7+
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
8+
RUN apk add --no-cache libc6-compat
9+
WORKDIR /app
10+
11+
# Install dependencies based on the preferred package manager
12+
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
13+
RUN \
14+
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
15+
elif [ -f package-lock.json ]; then npm ci; \
16+
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
17+
else echo "Lockfile not found." && exit 1; \
18+
fi
19+
20+
21+
# Rebuild the source code only when needed
22+
FROM base AS builder
23+
WORKDIR /app
24+
COPY --from=deps /app/node_modules ./node_modules
25+
COPY . .
26+
27+
# Next.js collects completely anonymous telemetry data about general usage.
28+
# Learn more here: https://nextjs.org/telemetry
29+
# Uncomment the following line in case you want to disable telemetry during the build.
30+
# ENV NEXT_TELEMETRY_DISABLED 1
31+
32+
RUN \
33+
if [ -f yarn.lock ]; then yarn run build; \
34+
elif [ -f package-lock.json ]; then npm run build; \
35+
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
36+
else echo "Lockfile not found." && exit 1; \
37+
fi
38+
39+
# Production image, copy all the files and run next
40+
FROM base AS runner
41+
WORKDIR /app
42+
43+
ENV NODE_ENV production
44+
# Uncomment the following line in case you want to disable telemetry during runtime.
45+
# ENV NEXT_TELEMETRY_DISABLED 1
46+
47+
RUN addgroup --system --gid 1001 nodejs
48+
RUN adduser --system --uid 1001 nextjs
49+
50+
# Remove this line if you do not have this folder
51+
COPY --from=builder /app/public ./public
52+
53+
# Set the correct permission for prerender cache
54+
RUN mkdir .next
55+
RUN chown nextjs:nodejs .next
56+
57+
# Automatically leverage output traces to reduce image size
58+
# https://nextjs.org/docs/advanced-features/output-file-tracing
59+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
60+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
61+
62+
USER nextjs
63+
64+
EXPOSE 3000
65+
66+
ENV PORT 3000
67+
68+
# server.js is created by next build from the standalone output
69+
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
70+
CMD HOSTNAME="0.0.0.0" node server.js

examples/astro/payload/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# blank
2+
3+
blank
4+
5+
## Attributes
6+
7+
- **Database**: mongodb
8+
- **Storage Adapter**: localDisk
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
version: '3'
2+
3+
services:
4+
payload:
5+
image: node:18-alpine
6+
ports:
7+
- '3000:3000'
8+
volumes:
9+
- .:/home/node/app
10+
- node_modules:/home/node/app/node_modules
11+
working_dir: /home/node/app/
12+
command: sh -c "corepack enable && corepack prepare pnpm@latest --activate && pnpm install && pnpm dev"
13+
depends_on:
14+
- mongo
15+
# - postgres
16+
env_file:
17+
- .env
18+
19+
# Ensure your DATABASE_URI uses 'mongo' as the hostname ie. mongodb://mongo/my-db-name
20+
mongo:
21+
image: mongo:latest
22+
ports:
23+
- '27017:27017'
24+
command:
25+
- --storageEngine=wiredTiger
26+
volumes:
27+
- data:/data/db
28+
logging:
29+
driver: none
30+
31+
# Uncomment the following to use postgres
32+
# postgres:
33+
# restart: always
34+
# image: postgres:latest
35+
# volumes:
36+
# - pgdata:/var/lib/postgresql/data
37+
# ports:
38+
# - "5432:5432"
39+
40+
volumes:
41+
data:
42+
# pgdata:
43+
node_modules:
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { dirname } from 'path'
2+
import { fileURLToPath } from 'url'
3+
import { FlatCompat } from '@eslint/eslintrc'
4+
5+
const __filename = fileURLToPath(import.meta.url)
6+
const __dirname = dirname(__filename)
7+
8+
const compat = new FlatCompat({
9+
baseDirectory: __dirname,
10+
})
11+
12+
const eslintConfig = [
13+
...compat.extends('next/core-web-vitals', 'next/typescript'),
14+
{
15+
rules: {
16+
'@typescript-eslint/ban-ts-comment': 'warn',
17+
'@typescript-eslint/no-empty-object-type': 'warn',
18+
'@typescript-eslint/no-explicit-any': 'warn',
19+
'@typescript-eslint/no-unused-vars': [
20+
'warn',
21+
{
22+
vars: 'all',
23+
args: 'after-used',
24+
ignoreRestSiblings: false,
25+
argsIgnorePattern: '^_',
26+
varsIgnorePattern: '^_',
27+
destructuredArrayIgnorePattern: '^_',
28+
caughtErrorsIgnorePattern: '^(_|ignore)',
29+
},
30+
],
31+
},
32+
},
33+
]
34+
35+
export default eslintConfig
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference types="next" />
2+
/// <reference types="next/image-types/global" />
3+
4+
// NOTE: This file should not be edited
5+
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.

0 commit comments

Comments
 (0)