Git Product home page Git Product logo

public-demo's Introduction

Payload Public Demo

This is the code that powers the official public demo of Payload CMS.

This demo utilizes the official Payload Website Template. Use it to power websites, blogs, or portfolios from small to enterprise. This repo includes a fully-working backend, enterprise-grade admin panel, and a beautifully designed, production-ready website.

Core features:

Quick Start

To spin up this example locally, follow these steps:

Clone

You can clone this repo to your own computer and play around super easily.

To do so, you'll need the following software:

  • Yarn or NPM
  • NodeJS version 10+
  • A Mongo Database - IMPORTANT: you need to either have MongoDB running locally, or have signed up for a free MongoDB Atlas server in order to test this repo locally.
Local installation steps:

1. Clone the repo by running the following command at your terminal:

git clone [email protected]:payloadcms/public-demo.git

Navigate to folder and install dependencies

Type cd ./public-demo and then yarn install to add all required dependencies.

Duplicate the example .env file and fill in your own values

Type cp .env.example .env in your terminal to make a copy of the example .env file, and then edit that file to fill in your own values.

Typically, the only line that you'll need to change within your new .env for local development is the DATABASE_URI value. If you have MongoDB running locally, then you can use the example connection string, but if you are using Mongo Atlas or similar, you'll want to fill this value in with your own connection string.

Fire up the development server

Finally, type yarn dev to start up the server and see it in action!

How it works

The Payload config is tailored specifically to the needs of most websites. It is pre-configured in the following ways:

Collections

See the Collections docs for details on how to extend this functionality.

  • Users (Authentication)

    Users are auth-enabled and encompass both admins and regular users based on the value of their roles field. Only admin users can access your admin panel to manage your website whereas user can authenticate on your front-end to leave comments and read premium content but have limited access to the platform. See Access Control for more details.

    For additional help, see the official Auth Example or the Authentication docs.

  • Posts

    Posts are used to generated blog posts, news articles, or any other type of content that is published over time. All posts are layout builder enabled so you can generate unique layouts for each post using layout-building blocks, see Layout Builder for more details. Posts are also draft-enabled so you can preview them before publishing them to your website, see Draft Preview for more details.

    Users can also leave comments on posts if they are logged in. Then, editors can log in to review and approve comments before they are published. See Comments for more details.

    Posts can also restrict access to content or digital assets behind authentication, see Premium Content for more details.

  • Comments (Collection)

    Comments are used to allow logged-in users to leave comments on posts. Comments are draft-enabled so admins can review and approve them before they are published to your website, see Comments for more details.

  • Projects

    Projects are used to showcase your work. All projects are layout builder enabled so you can generate unique layouts for each project using layout-building blocks, see Layout Builder for more details. Projects are also draft-enabled so you can preview them before publishing them to your website, see Draft Preview for more details.

  • Pages

    All pages are layout builder enabled so you can generate unique layouts for each page using layout-building blocks, see Layout Builder for more details. Pages are also draft-enabled so you can preview them before publishing them to your website, see Draft Preview for more details.

  • Media

    This is the uploads enabled collection used by pages, posts, and projects to contain media like images, videos, downloads, and other assets.

  • Categories

    A taxonomy used to group posts or projects together. Categories can be nested inside of one another, for example "News > Technology". See the official Payload Nested Docs Plugin for more details.

Globals

See the Globals docs for details on how to extend this functionality.

  • Header

    The data required by the header on your front-end like nav links.

  • Footer

    Same as above but for the footer of your site.

Access control

Basic role-based access control is setup to determine what users can and cannot do based on their roles, which are:

  • admin: They can access the Payload admin panel to manage your site. They can see all data and make all operations.
  • user: They cannot access the Payload admin panel and can perform limited operations based on their user (see below).

This applies to each collection in the following ways:

  • users: Only admins and the user themselves can access their profile. Anyone can create a user but only admins can delete users.
  • posts: Everyone can access published posts, but only admins can create, update, or delete them. Some posts may also have content that is only accessible to users who are logged in. See Premium Content for more details.
  • projects: Everyone can access published projects, but only admins can create, update, or delete them.
  • pages: Everyone can access published pages, but only admins can create, update, or delete them.
  • comments: Everyone can access published comments, but only admins can access draft comments. Users can create new comments but they will be saved as drafts until an admin approves them.

For more details on how to extend this functionality, see the Payload Access Control docs.

Premium Content

Posts can optionally restrict access to content or digital assets behind authentication. This will ensure that only members of your site can access the full post data and its resources. To do this, a premiumContent field is added to the posts collection with read access control set to check for an authenticated user on the request. Every time a user requests a post, this will only return data to those who have access to it:

{
  name: 'premiumContent',
  label: 'Premium Content',
  type: 'blocks',
  access: {
    read: isLoggedIn,
  },
  fields: [
    // content
  ]
}

Comments

Users can leave comments on posts for editors to review and approve before they are published to the website. To do this, a comments collection is added with drafts set to true so that all comments are saved as drafts and inaccessible until an admin approves them. Each comment references a single user and a doc for cross reference. To leave a comment you must be logged-in, and to publish a comment you must has the role admin.

Layout Builder

Create unique page, post, or project layouts for any type of content using a powerful layout builder. This demo comes pre-configured with the following layout building blocks:

  • Hero
  • Content
  • Media
  • Call To Action
  • Archive

Each block is fully designed and built into the front-end website that comes with this demo. See Website for more details.

Draft Preview

All posts, projects, and pages are draft-enabled so you can preview them before publishing them to your website. To do this, these collections use Versions with drafts set to true. This means that when you create a new post, project, or page, it will be saved as a draft and will not be visible on your website until you publish it. This also means that you can preview your draft before publishing it to your website. To do this, we automatically format a custom URL which redirects to your front-end to securely fetch the draft version of your content.

Since the front-end of this demo is statically generated, this also means that pages, posts, and projects will need to be regenerated as changes are made to published documents. To do this, we use an afterChange hook to regenerate the front-end when a document has changed and its _status is published.

For more details on how to extend this functionality, see the official Draft Preview Example.

SEO

This demo comes pre-configured with the official Payload SEO Plugin for complete SEO control from the admin panel. All SEO data is fully integrated into the front-end website that comes with this demo. See Website for more details.

Redirects

If you are migrating an existing site or moving content to a new URL, you can use the redirects collection to create a proper redirect from old URLs to new ones. This will ensure that proper request status codes are returned to search engines and that your users are not left with a broken link. This demo comes pre-configured with the official Payload Redirects Plugin for complete redirect control from the admin panel. All redirects are fully integrated into the front-end website that comes with this demo. See Website for more details.

Website

This demo includes a beautifully designed, production-ready front-end built with the Next.js App Router, served right alongside your Payload app in a single Express server. This makes is so that you can deploy both apps simultaneously and host them together. If you prefer a different front-end framework, this pattern works for any framework that supports a custom server. If you prefer to host your website separately from Payload, you can easily Eject the front-end out from this demo to swap in your own, or to use it as a standalone CMS. For more details, see the official Custom Server Example.

Core features:

Cache

Although Next.js includes a robust set of caching strategies out of the box, Payload Cloud proxies and caches all files through Cloudflare using the Official Cloud Plugin. This means that Next.js caching is not needed and is disabled by default. If you are hosting your app outside of Payload Cloud, you can easily reenable the Next.js caching mechanisms by removing the no-store directive from all fetch requests in ./src/app/_api and then removing all instances of export const dynamic = 'force-dynamic' from pages files, such as ./src/app/(pages)/[slug]/page.tsx. For more details, see the official Next.js Caching Docs.

Eject

If you prefer another front-end framework or would like to use Payload as a standalone CMS, you can easily eject the front-end from this demo. To eject, simply run yarn eject. This will uninstall all Next.js related dependencies and delete all files and folders related to the Next.js front-end. It also removes all custom routing from your server.ts file and updates your eslintrc.js.

Note: Your eject script may not work as expected if you've made significant modifications to your project. If you run into any issues, compare your project's dependencies and file structure with this demo. See ./src/eject for full details.

For more details on how setup a custom server, see the official Custom Server Example.

Questions

If you have any issues or questions, reach out to us on Discord or start a GitHub discussion.

public-demo's People

Contributors

alessiogr avatar alexjeffcott avatar creative-andrew avatar danribbens avatar denolfe avatar franciscolourenco avatar jacobsfletch avatar jarrodmflesch avatar jesschowdhury avatar jmikrut avatar matt-fidd avatar patrikkozak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

public-demo's Issues

Does not work correctly with create-payload-app (postgres breaks)

It seems that the payload/payload.config.ts is not correctly setup to work with create-payload-app cli which requires both // database-adapter-config-start and // database-adapter-config-end to work correctly.

07d9eb8#diff-a761e1902224d7e0a1c9362b0894878afe1b1fbc5b216b88c30c8595f76d8e9b

Unfortunately, the tests in create-payload-app do not attempt to cover this ‘template’, presumably because it is outside of the payload monorepo. Perhaps, testing npx create-payload-app here would be appropriate.

#33

The requested resource was not found when running `yarn dev`

I've been trying to get this to work for several hours now with no luck. Getting the following error when running yarn dev

Error updating global header: NotFound: The requested resource was not found.
    at findByID (/projects/payload-app/public-demo/node_modules/payload/src/collections/operations/findByID.ts:114:15)
    at processTicksAndRejections (node:internal/process/task_queues:95:5) {
  data: null,
  isOperational: true,
  isPublic: false,
  status: 404
}
NotFound: The requested resource was not found.
    at findByID (/projects/payload-app/public-demo/node_modules/payload/src/collections/operations/findByID.ts:114:15)
    at processTicksAndRejections (node:internal/process/task_queues:95:5) {
  data: null,
  isOperational: true,
  isPublic: false,
  status: 404
}
Error updating global settings: NotFound: The requested resource was not found.
    at findByID (/projects/payload-app/public-demo/node_modules/payload/src/collections/operations/findByID.ts:114:15)
    at processTicksAndRejections (node:internal/process/task_queues:95:5) {
  data: null,
  isOperational: true,
  isPublic: false,
  status: 404
}

To reproduce:

  1. clone repo
  2. update .env file to include your DB
  3. run yarn dev

Access control - user undefined

Hi!
I have been following some sample projects & am trying to set some user access rules.
For a collection "Posts" the access control is set as follows:
const isLoggedIn: Access<any, User> = ({ req: { user } }): boolean => { // Return true if user is logged in, false if not console.log(user); return Boolean(user); }

with the access defined as:
const Posts: CollectionConfig = { // the slug is used for naming the collection in the database and the APIs that are open. For example: api/posts/${id} slug: 'posts', admin: { // this is the name of a field which will be visible for the edit screen and is also used for relationship fields useAsTitle: 'title', // defaultColumns is used on the listing screen in the admin UI for the collection defaultColumns: [ 'title', 'category', 'publishDate', 'tags', 'status' ], group: 'Content' }, access: { create: isLoggedIn, update: isLoggedIn, delete: isLoggedIn, read: isLoggedIn

The read works fine (get request), however all other requet (delete/post/update) fail, since the user somehow ends up undefined for the request object. I checked the session cookie, this one gets send along correctly, so I wonder where the failure might be coming from.

How to host this public-demo on vps with custom domain?

Okay, I tried different approaches with no luck. Requests from localhost next site to localhost payload are working, but from custom.localhost to custom.localhost aren't. I'm using caddy for reverse proxy in docker and tried to host payload API on subdomain API.custom.localhost but fetch will throw error on server indicating address error. If I use client side requests instead of server components requests or curl it's working either way, but I still will have issues with displaying images on custom domain: request to this url https://custom_domain/_next/image?url=https%3A%2F%2Fcustom_domain%2Fmedia%2Fexample.png&w=2048&q=75 will throw error, even though url of the media is valid and I have custom_domain in next.config

  images: {
    remotePatterns: [
      { hostname: 'localhost', protocol: 'http' },
      { hostname: 'custom_domain', protocol: 'https' },
    ],
  },

custom_domain is obviously a placeholder for my real domain.
I see that next js public-demo is actually being hosted on cloudflare, so maybe that's why there is no prolblem with routing resolultions.

yarn update breaks demo

Please fix

user: Users.slug,
^
TypeError: Cannot read properties of undefined (reading 'slug')

Editing video rich text element

When adding a video element in the rich text editor, is there anyway to edit it? The video custom element is the best documentation I could find on implementing something similar, but I can't seem to figure out how to edit the value after submitting the form.

Steps to reproduce

  1. Edit a post in the demo cms
  2. Add a video with any id
  3. Attempt to edit the id

image

Thanks!

Seed fails on postgres

I assume this is happenning due to createdAt and updatedAt fields being empty.

error: invalid input syntax for type timestamp with time zone: ""
    at /Users/alex/Projects/payload-cms/payload-demo/node_modules/pg/lib/client.js:526:17
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /Users/alex/Projects/payload-cms/payload-demo/node_modules/src/node-postgres/session.ts:64:19
    at async upsertRow (/Users/alex/Projects/payload-cms/payload-demo/node_modules/@payloadcms/db-postgres/src/upsertRow/index.ts:63:24)
    at async Object.create (/Users/alex/Projects/payload-cms/payload-demo/node_modules/@payloadcms/db-postgres/src/create.ts:16:18)
    at async create (/Users/alex/Projects/payload-cms/payload-demo/node_modules/payload/src/collections/operations/create.ts:241:13) {
  length: 158,
  severity: 'ERROR',
  code: '22007',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: "unnamed portal parameter $4 = ''",
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'datetime.c',
  line: '3800',
  routine: 'DateTimeParseError'
}

Archive Block pagination doesn't work correctly for posts

Seems to work fine for projects, interestingly.

  1. Either add new posts or set pagination below 3 on the archive block
  2. As you switch through pages, observe that (some of) the same items are showing up on multiple pages. This prevents you from seeing all the posts as you paginate through.

I played with it a bit but haven't yet figured out exactly what's going on as I'm still learning payload (edit: I think I found the issue in #40 (comment)). If I find anything I'll share it here. I'm at least fairly certain that it's something on the server side rather than the client app.

Screen.Recording.2024-02-03.at.21.57.44.mov

Error when using npm to install dependencies

I receive the following error when using node 18 and npm. The instructions say you can use npm or yarn, but only yarn seems to work unless I'm missing something.

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: @payloadcms/[email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/payload
npm ERR!   payload@"^2.2.2" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer payload@"^0.18.5 || ^1.0.0" from @payloadcms/[email protected]
npm ERR! node_modules/@payloadcms/plugin-form-builder
npm ERR!   @payloadcms/plugin-form-builder@"^1.0.15" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 

If npm is not actually supported, I'd be happy to contribute a PR to update the docs.

could not resolve peer dependency

npm i on a fresh clone

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: @payloadcms/[email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/payload
npm ERR!   payload@"^2.2.2" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer payload@"^0.18.5 || ^1.0.0" from @payloadcms/[email protected]
npm ERR! node_modules/@payloadcms/plugin-form-builder
npm ERR!   @payloadcms/plugin-form-builder@"^1.0.15" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! 

auto load all collection.

Request to load all collections automatically,
it's so hard to import each collection evry time in payload.config.

Could not resolve dependency: @payloadcms/plugin-form-builder

Tried cloning the repo and running npm install (after deleting yarn.lock)

 code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/payload
npm ERR!   payload@"^1.1.1" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer payload@"^0.18.5" from @payloadcms/[email protected]
npm ERR! node_modules/@payloadcms/plugin-form-builder
npm ERR!   @payloadcms/plugin-form-builder@"^1.0.2" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! See /Users/isaiahdahl/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/isaiahdahl/.npm/_logs/2022-09-24T05_35_54_454Z-debug-0.log

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.