Initial commit
This commit is contained in:
27
skills/pocketbase/assets/Caddyfile
Normal file
27
skills/pocketbase/assets/Caddyfile
Normal file
@@ -0,0 +1,27 @@
|
||||
# PocketBase Caddy Configuration
|
||||
# This provides automatic HTTPS and reverse proxy
|
||||
|
||||
yourdomain.com {
|
||||
# Redirect HTTP to HTTPS
|
||||
redir https://{host}{uri} permanent
|
||||
|
||||
# Proxy to PocketBase
|
||||
reverse_proxy pocketbase:8090
|
||||
|
||||
# Enable gzip compression
|
||||
encode gzip
|
||||
|
||||
# Set security headers
|
||||
header {
|
||||
X-Content-Type-Options nosniff
|
||||
X-Frame-Options DENY
|
||||
X-XSS-Protection "1; mode=block"
|
||||
Strict-Transport-Security "max-age=31536000; includeSubDomains"
|
||||
}
|
||||
}
|
||||
|
||||
# For development (HTTP only)
|
||||
localhost {
|
||||
reverse_proxy pocketbase:8090
|
||||
encode gzip
|
||||
}
|
||||
104
skills/pocketbase/assets/collection-schema-template.json
Normal file
104
skills/pocketbase/assets/collection-schema-template.json
Normal file
@@ -0,0 +1,104 @@
|
||||
{
|
||||
"name": "CollectionName",
|
||||
"type": "base",
|
||||
"system": false,
|
||||
"schema": [
|
||||
{
|
||||
"id": "field_id",
|
||||
"name": "Field Name",
|
||||
"type": "text",
|
||||
"required": true,
|
||||
"options": {
|
||||
"min": 1,
|
||||
"max": 200
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "text_field",
|
||||
"name": "Text Field",
|
||||
"type": "text",
|
||||
"required": false,
|
||||
"options": {
|
||||
"min": 0,
|
||||
"max": 1000
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "number_field",
|
||||
"name": "Number Field",
|
||||
"type": "number",
|
||||
"required": false,
|
||||
"options": {
|
||||
"min": 0,
|
||||
"max": 100
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "bool_field",
|
||||
"name": "Boolean Field",
|
||||
"type": "bool",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"id": "email_field",
|
||||
"name": "Email Field",
|
||||
"type": "email",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"id": "url_field",
|
||||
"name": "URL Field",
|
||||
"type": "url",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"id": "date_field",
|
||||
"name": "Date Field",
|
||||
"type": "date",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"id": "json_field",
|
||||
"name": "JSON Field",
|
||||
"type": "json",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"id": "select_field",
|
||||
"name": "Select Field",
|
||||
"type": "select",
|
||||
"required": false,
|
||||
"options": {
|
||||
"values": ["option1", "option2", "option3"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "relation_field",
|
||||
"name": "Relation Field",
|
||||
"type": "relation",
|
||||
"required": false,
|
||||
"options": {
|
||||
"collectionId": "collection_id_here",
|
||||
"cascadeDelete": false,
|
||||
"maxSelect": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "file_field",
|
||||
"name": "File Field",
|
||||
"type": "file",
|
||||
"required": false,
|
||||
"options": {
|
||||
"maxSelect": 1,
|
||||
"maxSize": 10485760,
|
||||
"mimeTypes": ["image/jpeg", "image/png"],
|
||||
"thumbs": ["100x100", "300x300"]
|
||||
}
|
||||
}
|
||||
],
|
||||
"listRule": "",
|
||||
"viewRule": "",
|
||||
"createRule": "@request.auth.id != ''",
|
||||
"updateRule": "field = @request.auth.id",
|
||||
"deleteRule": "field = @request.auth.id"
|
||||
}
|
||||
35
skills/pocketbase/assets/docker-compose.yml
Normal file
35
skills/pocketbase/assets/docker-compose.yml
Normal file
@@ -0,0 +1,35 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
pocketbase:
|
||||
image: ghcr.io/pocketbase/pocketbase:latest
|
||||
command:
|
||||
- serve
|
||||
- --http=0.0.0.0:8090
|
||||
container_name: pocketbase
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "8090:8090"
|
||||
volumes:
|
||||
- ./pb_data:/pb/pb_data
|
||||
environment:
|
||||
- PB_PUBLIC_DIR=/pb/public
|
||||
|
||||
# Optional: Add a reverse proxy (Caddy)
|
||||
caddy:
|
||||
image: caddy:2
|
||||
container_name: pocketbase-proxy
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "80:80"
|
||||
- "443:443"
|
||||
volumes:
|
||||
- ./Caddyfile:/etc/caddy/Caddyfile
|
||||
- caddy_data:/data
|
||||
- caddy_config:/config
|
||||
depends_on:
|
||||
- pocketbase
|
||||
|
||||
volumes:
|
||||
caddy_data:
|
||||
caddy_config:
|
||||
275
skills/pocketbase/assets/frontend-template.html
Normal file
275
skills/pocketbase/assets/frontend-template.html
Normal file
@@ -0,0 +1,275 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>PocketBase Frontend Template</title>
|
||||
<script src="https://unpkg.com/pocketbase@latest/dist/pocketbase.umd.js"></script>
|
||||
<style>
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
||||
max-width: 800px;
|
||||
margin: 50px auto;
|
||||
padding: 20px;
|
||||
}
|
||||
.card {
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
margin: 20px 0;
|
||||
}
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
input, textarea, button {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
margin: 5px 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
button {
|
||||
background: #007bff;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
button:hover {
|
||||
background: #0056b3;
|
||||
}
|
||||
button:disabled {
|
||||
background: #ccc;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.error {
|
||||
color: red;
|
||||
margin: 10px 0;
|
||||
}
|
||||
.success {
|
||||
color: green;
|
||||
margin: 10px 0;
|
||||
}
|
||||
#posts {
|
||||
margin-top: 20px;
|
||||
}
|
||||
.post {
|
||||
border-left: 3px solid #007bff;
|
||||
padding-left: 15px;
|
||||
margin: 15px 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>PocketBase Frontend Template</h1>
|
||||
|
||||
<!-- Auth Section -->
|
||||
<div id="auth-section" class="card">
|
||||
<h2>Authentication</h2>
|
||||
<div id="login-form">
|
||||
<h3>Login</h3>
|
||||
<input type="email" id="login-email" placeholder="Email" required>
|
||||
<input type="password" id="login-password" placeholder="Password" required>
|
||||
<button onclick="login()">Login</button>
|
||||
<div id="login-message"></div>
|
||||
</div>
|
||||
|
||||
<div id="register-form" style="margin-top: 20px;">
|
||||
<h3>Register</h3>
|
||||
<input type="email" id="register-email" placeholder="Email" required>
|
||||
<input type="text" id="register-name" placeholder="Name" required>
|
||||
<input type="password" id="register-password" placeholder="Password" required>
|
||||
<input type="password" id="register-password-confirm" placeholder="Confirm Password" required>
|
||||
<button onclick="register()">Register</button>
|
||||
<div id="register-message"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- User Info Section -->
|
||||
<div id="user-section" class="card hidden">
|
||||
<h2>Welcome, <span id="user-email"></span></h2>
|
||||
<button onclick="logout()">Logout</button>
|
||||
</div>
|
||||
|
||||
<!-- Create Post Section -->
|
||||
<div id="create-section" class="card hidden">
|
||||
<h2>Create Post</h2>
|
||||
<input type="text" id="post-title" placeholder="Post Title" required>
|
||||
<textarea id="post-content" placeholder="Post Content" rows="5" required></textarea>
|
||||
<button onclick="createPost()">Create Post</button>
|
||||
<div id="create-message"></div>
|
||||
</div>
|
||||
|
||||
<!-- Posts Section -->
|
||||
<div id="posts" class="card hidden">
|
||||
<h2>Posts</h2>
|
||||
<button onclick="loadPosts()">Refresh Posts</button>
|
||||
<div id="posts-list"></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Initialize PocketBase client
|
||||
const pb = new PocketBase('http://127.0.0.1:8090');
|
||||
|
||||
// Check if user is already logged in
|
||||
checkAuth();
|
||||
|
||||
async function checkAuth() {
|
||||
if (pb.authStore.isValid) {
|
||||
const user = pb.authStore.model;
|
||||
document.getElementById('auth-section').classList.add('hidden');
|
||||
document.getElementById('user-section').classList.remove('hidden');
|
||||
document.getElementById('create-section').classList.remove('hidden');
|
||||
document.getElementById('posts').classList.remove('hidden');
|
||||
document.getElementById('user-email').textContent = user.email;
|
||||
loadPosts();
|
||||
}
|
||||
}
|
||||
|
||||
async function login() {
|
||||
const email = document.getElementById('login-email').value;
|
||||
const password = document.getElementById('login-password').value;
|
||||
const messageDiv = document.getElementById('login-message');
|
||||
|
||||
try {
|
||||
const authData = await pb.collection('users').authWithPassword(email, password);
|
||||
messageDiv.className = 'success';
|
||||
messageDiv.textContent = 'Login successful!';
|
||||
checkAuth();
|
||||
} catch (e) {
|
||||
messageDiv.className = 'error';
|
||||
messageDiv.textContent = e.data?.message || 'Login failed. Please check your credentials.';
|
||||
}
|
||||
}
|
||||
|
||||
async function register() {
|
||||
const email = document.getElementById('register-email').value;
|
||||
const name = document.getElementById('register-name').value;
|
||||
const password = document.getElementById('register-password').value;
|
||||
const passwordConfirm = document.getElementById('register-password-confirm').value;
|
||||
const messageDiv = document.getElementById('register-message');
|
||||
|
||||
if (password !== passwordConfirm) {
|
||||
messageDiv.className = 'error';
|
||||
messageDiv.textContent = 'Passwords do not match.';
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const authData = await pb.collection('users').create({
|
||||
email: email,
|
||||
password: password,
|
||||
passwordConfirm: passwordConfirm,
|
||||
name: name
|
||||
});
|
||||
|
||||
// Auto-login after registration
|
||||
await pb.collection('users').authWithPassword(email, password);
|
||||
|
||||
messageDiv.className = 'success';
|
||||
messageDiv.textContent = 'Registration successful!';
|
||||
checkAuth();
|
||||
} catch (e) {
|
||||
messageDiv.className = 'error';
|
||||
messageDiv.textContent = e.data?.message || 'Registration failed.';
|
||||
}
|
||||
}
|
||||
|
||||
function logout() {
|
||||
pb.authStore.clear();
|
||||
location.reload();
|
||||
}
|
||||
|
||||
async function createPost() {
|
||||
const title = document.getElementById('post-title').value;
|
||||
const content = document.getElementById('post-content').value;
|
||||
const messageDiv = document.getElementById('create-message');
|
||||
|
||||
if (!pb.authStore.isValid) {
|
||||
messageDiv.className = 'error';
|
||||
messageDiv.textContent = 'You must be logged in to create a post.';
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await pb.collection('posts').create({
|
||||
title: title,
|
||||
content: content,
|
||||
author: pb.authStore.model.id,
|
||||
status: 'published'
|
||||
});
|
||||
|
||||
messageDiv.className = 'success';
|
||||
messageDiv.textContent = 'Post created successfully!';
|
||||
document.getElementById('post-title').value = '';
|
||||
document.getElementById('post-content').value = '';
|
||||
loadPosts();
|
||||
} catch (e) {
|
||||
messageDiv.className = 'error';
|
||||
messageDiv.textContent = e.data?.message || 'Failed to create post.';
|
||||
}
|
||||
}
|
||||
|
||||
async function loadPosts() {
|
||||
const postsList = document.getElementById('posts-list');
|
||||
postsList.innerHTML = '<p>Loading...</p>';
|
||||
|
||||
try {
|
||||
const records = await pb.collection('posts').getList(1, 50, {
|
||||
sort: '-created',
|
||||
expand: 'author'
|
||||
});
|
||||
|
||||
if (records.items.length === 0) {
|
||||
postsList.innerHTML = '<p>No posts yet. Be the first to create one!</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
postsList.innerHTML = records.items.map(post => {
|
||||
const author = post.expand?.author;
|
||||
return `
|
||||
<div class="post">
|
||||
<h3>${escapeHtml(post.title)}</h3>
|
||||
<p>${escapeHtml(post.content)}</p>
|
||||
<small>By ${author?.name || 'Unknown'} on ${new Date(post.created).toLocaleString()}</small>
|
||||
${post.author === pb.authStore.model?.id ? `
|
||||
<div style="margin-top: 10px;">
|
||||
<button onclick="editPost('${post.id}')" style="background: #28a745;">Edit</button>
|
||||
<button onclick="deletePost('${post.id}')" style="background: #dc3545; margin-left: 5px;">Delete</button>
|
||||
</div>
|
||||
` : ''}
|
||||
</div>
|
||||
`;
|
||||
}).join('');
|
||||
} catch (e) {
|
||||
postsList.innerHTML = `<p class="error">Failed to load posts: ${e.message}</p>`;
|
||||
}
|
||||
}
|
||||
|
||||
async function deletePost(id) {
|
||||
if (!confirm('Are you sure you want to delete this post?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await pb.collection('posts').delete(id);
|
||||
loadPosts();
|
||||
} catch (e) {
|
||||
alert('Failed to delete post: ' + (e.data?.message || e.message));
|
||||
}
|
||||
}
|
||||
|
||||
function escapeHtml(text) {
|
||||
const div = document.createElement('div');
|
||||
div.textContent = text;
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
// Set up real-time subscription (if supported)
|
||||
pb.collection('posts').subscribe('*', function (e) {
|
||||
console.log('Real-time event:', e);
|
||||
// Reload posts when changes occur
|
||||
loadPosts();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user