generated from autonomic-cooperative/astro-payload-template
Initial commit
This commit is contained in:
25
payload/src/collections/Media.ts
Normal file
25
payload/src/collections/Media.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { CollectionConfig } from "payload/types";
|
||||
|
||||
export const Media: CollectionConfig = {
|
||||
slug: "media",
|
||||
admin: {},
|
||||
access: {
|
||||
read: (): boolean => true,
|
||||
create: () => true,
|
||||
update: () => true,
|
||||
},
|
||||
upload: {
|
||||
staticURL: "/media",
|
||||
staticDir: "media",
|
||||
mimeTypes: ["image/*"],
|
||||
},
|
||||
|
||||
fields: [
|
||||
{
|
||||
name: "alt",
|
||||
type: "text",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export default Media;
|
98
payload/src/collections/Posts.ts
Normal file
98
payload/src/collections/Posts.ts
Normal file
@ -0,0 +1,98 @@
|
||||
import { CollectionConfig } from "payload/types";
|
||||
const Posts: CollectionConfig = {
|
||||
slug: "posts",
|
||||
admin: {
|
||||
defaultColumns: ["title", "author", "status"],
|
||||
useAsTitle: "title",
|
||||
},
|
||||
access: {
|
||||
read: () => true,
|
||||
create: () => true,
|
||||
update: () => true,
|
||||
},
|
||||
hooks: {
|
||||
afterChange: [
|
||||
async () => {
|
||||
console.log(process.env.TOKEN);
|
||||
|
||||
try {
|
||||
process.env.NODE_ENV !== "development" &&
|
||||
console.log(
|
||||
await fetch(
|
||||
`https://api.github.com/repos/${process.env.REPOSITORY}/dispatches`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
Accept: "application/vnd.github.everest-preview+json",
|
||||
Authorization: `token ${process.env.TOKEN}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
event_type: "payload_update",
|
||||
}),
|
||||
}
|
||||
)
|
||||
);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
},
|
||||
],
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
name: "title",
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
name: "hallo",
|
||||
type: "text",
|
||||
},
|
||||
{
|
||||
name: "publishedDate",
|
||||
type: "date",
|
||||
},
|
||||
|
||||
{
|
||||
name: "content",
|
||||
type: "richText",
|
||||
admin: {
|
||||
elements: ["h2", "h3", "h4", "link", "ol", "ul", "upload"],
|
||||
leaves: ["bold", "italic", "underline"],
|
||||
upload: {
|
||||
collections: {
|
||||
media: {
|
||||
fields: [
|
||||
{
|
||||
name: "imagel",
|
||||
type: "upload",
|
||||
relationTo: "media",
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "status",
|
||||
type: "select",
|
||||
options: [
|
||||
{
|
||||
value: "draft",
|
||||
label: "Draft",
|
||||
},
|
||||
{
|
||||
value: "published",
|
||||
label: "Published",
|
||||
},
|
||||
],
|
||||
defaultValue: "draft",
|
||||
admin: {
|
||||
position: "sidebar",
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export default Posts;
|
21
payload/src/collections/Users.ts
Normal file
21
payload/src/collections/Users.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { CollectionConfig } from 'payload/types';
|
||||
|
||||
const Users: CollectionConfig = {
|
||||
slug: 'users',
|
||||
auth: true,
|
||||
admin: {
|
||||
useAsTitle: 'email',
|
||||
},
|
||||
access: {
|
||||
read: () => true,
|
||||
},
|
||||
fields: [
|
||||
// Email added by default
|
||||
{
|
||||
name: 'name',
|
||||
type: 'text',
|
||||
}
|
||||
],
|
||||
};
|
||||
|
||||
export default Users;
|
26
payload/src/payload.config.ts
Normal file
26
payload/src/payload.config.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { buildConfig } from "payload/config";
|
||||
import path from "path";
|
||||
import Posts from "@/collections/Posts";
|
||||
import Users from "@/collections/Users";
|
||||
import Media from "@/collections/Media";
|
||||
|
||||
export default buildConfig({
|
||||
serverURL: process.env.PAYLOAD_URL,
|
||||
admin: {
|
||||
user: Users.slug,
|
||||
webpack: (config) => ({
|
||||
...config,
|
||||
resolve: {
|
||||
...config.resolve,
|
||||
alias: {
|
||||
...config.resolve.alias,
|
||||
"@": path.resolve(__dirname, "./"),
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
collections: [Posts, Users, Media],
|
||||
typescript: {
|
||||
outputFile: path.resolve("/", "types.ts"),
|
||||
},
|
||||
});
|
21
payload/src/server.ts
Normal file
21
payload/src/server.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import express from "express";
|
||||
import payload from "payload";
|
||||
|
||||
require("dotenv").config();
|
||||
const app = express();
|
||||
|
||||
app.get("/", (_, res) => {
|
||||
res.redirect("/admin");
|
||||
});
|
||||
|
||||
payload.init({
|
||||
secret: process.env.PAYLOAD_SECRET,
|
||||
mongoURL: process.env.MONGODB_URI,
|
||||
express: app,
|
||||
onInit: () => {
|
||||
payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`);
|
||||
},
|
||||
});
|
||||
|
||||
app.use("/media", express.static("media"));
|
||||
app.listen(process.env.PAYLOAD_PORT);
|
Reference in New Issue
Block a user