Skip to content

Commit a60308a

Browse files
committed
Initial commit
0 parents  commit a60308a

12 files changed

+7897
-0
lines changed

.env.example

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
MONGODB_URI=mongodb://127.0.0.1/payload-template-blank
2+
PAYLOAD_SECRET=YOUR_SECRET_HERE

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
build
2+
dist
3+
/media
4+
node_modules
5+
.DS_Store
6+
.env

Dockerfile

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM node:18.8-alpine as base
2+
3+
FROM base as builder
4+
5+
WORKDIR /home/node/app
6+
COPY package*.json ./
7+
8+
COPY . .
9+
RUN yarn install
10+
RUN yarn build
11+
12+
FROM base as runtime
13+
14+
ENV NODE_ENV=production
15+
ENV PAYLOAD_CONFIG_PATH=dist/payload.config.js
16+
17+
WORKDIR /home/node/app
18+
COPY package*.json ./
19+
20+
RUN yarn install --production
21+
COPY --from=builder /home/node/app/dist ./dist
22+
COPY --from=builder /home/node/app/build ./build
23+
24+
EXPOSE 3000
25+
26+
CMD ["node", "dist/server.js"]

README.md

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Payload Blank Template
2+
3+
A blank template for [Payload](https://github.com/payloadcms/payload) to help you get up and running quickly. This repo may have been created by running `npx create-payload-app` and selecting the "blank" template or by cloning this template on [Payload Cloud](https://payloadcms.com/new/clone/blank).
4+
5+
See the official [Examples Directory](https://github.com/payloadcms/payload/tree/master/examples) for details on how to use Payload in a variety of different ways.
6+
7+
## Development
8+
9+
To spin up the project locally, follow these steps:
10+
11+
1. First clone the repo
12+
1. Then `cd YOUR_PROJECT_REPO && cp .env.example .env`
13+
1. Next `yarn && yarn dev` (or `docker-compose up`, see [Docker](#docker))
14+
1. Now `open http://localhost:8000/admin` to access the admin panel
15+
1. Create your first admin user using the form on the page
16+
17+
That's it! Changes made in `./src` will be reflected in your app.
18+
19+
### Docker
20+
21+
Alternatively, you can use [Docker](https://www.docker.com) to spin up this project locally. To do so, follow these steps:
22+
23+
1. Follow [steps 1 and 2 from above](#development), the docker-compose file will automatically use the `.env` file in your project root
24+
1. Next run `docker-compose up`
25+
1. Follow [steps 4 and 5 from above](#development) to login and create your first admin user
26+
27+
That's it! The Docker instance will help you get up and running quickly while also standardizing the development environment across your teams.
28+
29+
## Production
30+
31+
To run Payload in production, you need to build and serve the Admin panel. To do so, follow these steps:
32+
33+
1. First invoke the `payload build` script by running `yarn build` or `npm run build` in your project root. This creates a `./build` directory with a production-ready admin bundle.
34+
1. Then run `yarn serve` or `npm run serve` to run Node in production and serve Payload from the `./build` directory.
35+
36+
### Deployment
37+
38+
The easiest way to deploy your project is to use [Payload Cloud](https://payloadcms.com/new/import), a one-click hosting solution to deploy production-ready instances of your Payload apps directly from your GitHub repo. You can also deploy your app manually, check out the [deployment documentation](https://payloadcms.com/docs/production/deployment) for full details.
39+
40+
## Questions
41+
42+
If you have any issues or questions, reach out to us on [Discord](https://discord.com/invite/payload) or start a [GitHub discussion](https://github.com/payloadcms/payload/discussions).

docker-compose.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
version: '3'
2+
3+
services:
4+
5+
payload:
6+
image: node:18-alpine
7+
ports:
8+
- "3000:3000"
9+
volumes:
10+
- .:/home/node/app
11+
- node_modules:/home/node/app/node_modules
12+
working_dir: /home/node/app/
13+
command: sh -c "yarn install && yarn dev"
14+
depends_on:
15+
- mongo
16+
env_file:
17+
- .env
18+
19+
mongo:
20+
image: mongo:latest
21+
ports:
22+
- "27017:27017"
23+
command:
24+
- --storageEngine=wiredTiger
25+
volumes:
26+
- data:/data/db
27+
logging:
28+
driver: none
29+
30+
volumes:
31+
data:
32+
node_modules:

nodemon.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"ext": "ts",
3+
"exec": "ts-node src/server.ts"
4+
}

package.json

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "template-blank",
3+
"description": "A blank template to get started with Payload",
4+
"version": "1.0.0",
5+
"main": "dist/server.js",
6+
"license": "MIT",
7+
"scripts": {
8+
"dev": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts nodemon",
9+
"build:payload": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload build",
10+
"build:server": "tsc",
11+
"build": "yarn copyfiles && yarn build:payload && yarn build:server",
12+
"serve": "cross-env PAYLOAD_CONFIG_PATH=dist/payload.config.js NODE_ENV=production node dist/server.js",
13+
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png}\" dist/",
14+
"generate:types": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:types",
15+
"generate:graphQLSchema": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:graphQLSchema"
16+
},
17+
"dependencies": {
18+
"@payloadcms/plugin-cloud": "^0.0.10",
19+
"cross-env": "^7.0.3",
20+
"dotenv": "^8.2.0",
21+
"express": "^4.17.1",
22+
"payload": "latest"
23+
},
24+
"devDependencies": {
25+
"@types/express": "^4.17.9",
26+
"copyfiles": "^2.4.1",
27+
"nodemon": "^2.0.6",
28+
"ts-node": "^9.1.1",
29+
"typescript": "^4.8.4"
30+
}
31+
}

src/collections/Users.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { CollectionConfig } from 'payload/types';
2+
3+
const Users: CollectionConfig = {
4+
slug: 'users',
5+
auth: true,
6+
admin: {
7+
useAsTitle: 'email',
8+
},
9+
fields: [
10+
// Email added by default
11+
// Add more fields as needed
12+
],
13+
};
14+
15+
export default Users;

src/payload.config.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { buildConfig } from 'payload/config';
2+
import path from 'path';
3+
import Users from './collections/Users';
4+
import { payloadCloud } from '@payloadcms/plugin-cloud';
5+
6+
export default buildConfig({
7+
admin: {
8+
user: Users.slug,
9+
},
10+
collections: [
11+
Users,
12+
],
13+
typescript: {
14+
outputFile: path.resolve(__dirname, 'payload-types.ts'),
15+
},
16+
graphQL: {
17+
schemaOutputFile: path.resolve(__dirname, 'generated-schema.graphql'),
18+
},
19+
plugins: [
20+
payloadCloud()
21+
]
22+
});

src/server.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import express from 'express';
2+
import payload from 'payload';
3+
4+
require('dotenv').config();
5+
const app = express();
6+
7+
// Redirect root to Admin panel
8+
app.get('/', (_, res) => {
9+
res.redirect('/admin');
10+
});
11+
12+
const start = async () => {
13+
// Initialize Payload
14+
await payload.init({
15+
secret: process.env.PAYLOAD_SECRET,
16+
mongoURL: process.env.MONGODB_URI,
17+
express: app,
18+
onInit: async () => {
19+
payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`)
20+
},
21+
})
22+
23+
// Add your own express routes here
24+
25+
app.listen(3000);
26+
}
27+
28+
start();

tsconfig.json

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"lib": [
5+
"dom",
6+
"dom.iterable",
7+
"esnext"
8+
],
9+
"allowJs": true,
10+
"strict": false,
11+
"esModuleInterop": true,
12+
"skipLibCheck": true,
13+
"outDir": "./dist",
14+
"rootDir": "./src",
15+
"jsx": "react",
16+
"paths": {
17+
"payload/generated-types": [
18+
"./src/payload-types.ts",
19+
],
20+
}
21+
},
22+
"include": [
23+
"src"
24+
],
25+
"exclude": [
26+
"node_modules",
27+
"dist",
28+
"build",
29+
],
30+
"ts-node": {
31+
"transpileOnly": true,
32+
"swc": true,
33+
}
34+
}

0 commit comments

Comments
 (0)