@luckydye/astro-payload
TypeScript icon, indicating that this package has built-in type declarations

0.0.19 • Public • Published

Astro integration for Payload CMS

This integration creates a SSR route for the payload cms with the node adapter even in dev mode.

Example project: https://github.com/luckydye/astro-payload/tree/main/apps/web

Options

interface Options {
	// entry file path for the payload route
	payloadRoute: string;
}

Example Astro config:

// /astro.config.ts
import { defineConfig } from "astro/config";
import payload from "@luckydye/astro-payload";
import node from "@astrojs/node";

// https://astro.build/config
export default defineConfig({
	srcDir: "src",
	output: "server",
	adapter: node({
		mode: "standalone",
	}),
	integrations: [
		payload({
			payloadRoute: "./payload.ts",
		}),
	],
});
// ./payload.ts
import payload from "payload";
import payloadConfig from "./payload.config";
import express from "express";
import type { APIRoute } from "astro";

async function startPayload() {
	const app = express();
	await payload.init({
		secret: process.env.PAYLOAD_SECRET || "",
		mongoURL: process.env.DB_URI || "",
		mongoOptions: {
			user: process.env.DB_ROOT_USER,
			pass: process.env.DB_ROOT_PASS,
			dbName: process.env.DB_NAME,
		},
		express: app,
		config: payloadConfig,
	});
	// starting payload on a different port
	app.listen(process.env.PAYLOAD_PORT);
}

const payloadServer = startPayload();

export const all: APIRoute = async () => {
	await payloadServer;

	return new Response(null, {
		status: 404,
	});
};

Dependents (0)

Package Sidebar

Install

npm i @luckydye/astro-payload

Weekly Downloads

1

Version

0.0.19

License

none

Unpacked Size

3.68 kB

Total Files

4

Last publish

Collaborators

  • luckydye