Skip to main content

pb-extend

Extend PocketBase with custom hooks and routes in JS or Go. Use when user wants to add custom API routes, modify PocketBase behavior, or add server-side logic.

설치로 이동

소스 정보

저장소
spinspire/pocketbase-sveltekit-starter
최근 소스 활동
2026년 8월 22일 18:20
감지된 SKILL.md 언어
영어
스타
509
포크
76

설치 방법

기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.

소스 파일 검토

설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.

SKILL.md 표시 중

SKILL.md
소스 지침 · 읽기 전용 미리보기
name
pb-extend
description
Extend PocketBase with custom hooks and routes in JS or Go. Use when user wants to add custom API routes, modify PocketBase behavior, or add server-side logic.
allowed-tools
Bash
license
MIT
authors
SpinSpire Team
# PocketBase Extending Reference: https://pocketbase.io/docs/js-overview/ | https://pocketbase.io/docs/go-overview/ Extend PocketBase with custom hooks and routes in JS or Go. ## JS Hooks (pb_hooks/) Drop `*.pb.js` files in `pb_hooks/`: ```javascript // pb_hooks/myhook.pb.js /// <reference path="../pb_data/types.d.ts" /> router.api.post('/custom-route', async (e) => { const body = e.request.body // ... process return e.json({ result: 'ok' }) }) // On record create onRecordCreateRequest((e) => { if (!e.record.get('email').endsWith('@company.com')) { return e.badRequest('Use company email') } return e.next() }) ``` **Rules:** - Always call `e.next()` / `e.Next()` in hooks - Variables outside handlers are undefined at runtime - Use `require()` for shared config (CJS only, no ESM) ## Go Hooks (migrations/) Versioned migrations in `migrations/`: ```go package migrations import ( "github.com/pocketbase/pocketbase/migrations" "github.com/pocketbase/pocketbase/tools/types" ) func init() { migrations.Register(func(app *pocketbase.App) error { // Custom logic return nil }, func(app *pocketbase.App) error { // Rollback logic return nil }) } ``` ## Custom Routes ```javascript // Add to pb_hooks router.api.post('/api/myapp/send-email', async (e) => { const data = await e.request.json() await sendEmail(data.to, data.subject) return e.json({ sent: true }) }, middleware.RequireAuth()) ``` ## Key Hook Events | Event | Purpose | |-------|---------| | `onRecordCreateRequest` | Before record creation | | `onRecordUpdateRequest` | Before record update | | `onRecordDeleteRequest` | Before record deletion | | `OnRecordEnrich` | Shape response (incl. realtime) | | `OnRecordRequest` | HTTP-only response shaping | | `OnBeforeServe` | Modify router before serving | ## Migrations **System fields**: Collections created via migration files **must** include `created` and `updated` system fields. **Auto-migrate**: Collections changed via Admin UI auto-generate migrations in `pb_migrations/` **Manual JS migration**: ```javascript // pb_migrations/1700000000_seed_data.js migrate((up, down) => { up((db) => { db.createCollection('categories', { /* ... */ }) }) down((db) => { db.dropCollection('categories') }) }) ``` ## Useful Settings ```javascript // Read at runtime const settings = require('../pb_settings/config.js') // Access app in hooks router.use(async (e) => { const app = e.app // ... }) ```
GitHub에서 보기