mirror of
https://github.com/pockethost/pockethost.git
synced 2025-06-03 20:56:40 +00:00
chore: dev environment fixes
This commit is contained in:
parent
64b21bd2db
commit
ef022073a2
@ -4,7 +4,7 @@ PUBLIC_APP_DB=pockethost-central
|
||||
DAEMON_PB_BIN_DIR=`pwd`/packages/pocketbase/dist
|
||||
DAEMON_PB_DATA_DIR=`pwd`/.data
|
||||
DAEMON_PB_USERNAME=admin@pockethost.test
|
||||
DAEMON_PB_PASSWORD=password
|
||||
DAEMON_PB_PASSWORD=admin@pockethost.test
|
||||
DAEMON_PB_PORT=8090
|
||||
DAEMON_IDLE_TTL=5000
|
||||
DAEMON_PB_BACKUP_SLEEP=100
|
||||
|
@ -11,7 +11,7 @@ export const safeCatch = <TIn extends any[], TOut>(
|
||||
const _c = c++
|
||||
const uuid = `${name}:${_c}`
|
||||
const pfx = `safeCatch:${uuid}`
|
||||
const { raw, error, warn } = logger().create(pfx)
|
||||
const { raw, error, warn, dbg } = logger().create(pfx)
|
||||
raw(`args`, args)
|
||||
const tid = setTimeout(() => {
|
||||
error(`timeout ${timeoutMs}ms waiting for ${pfx}`)
|
||||
@ -29,6 +29,7 @@ export const safeCatch = <TIn extends any[], TOut>(
|
||||
warn(
|
||||
`PocketBase API error: It looks like you don't have permission to make this request.`
|
||||
)
|
||||
dbg(JSON.stringify(e, null, 2))
|
||||
} else if (e.status === 0) {
|
||||
warn(`Client request aborted (duplicate)`)
|
||||
} else {
|
||||
|
@ -33,7 +33,7 @@ export const schema: Collection_Serialized[] = [
|
||||
unique: false,
|
||||
options: {
|
||||
maxSelect: 1,
|
||||
collectionId: 'systemprofiles0',
|
||||
collectionId: '_pb_users_auth_',
|
||||
cascadeDelete: false,
|
||||
},
|
||||
},
|
||||
@ -105,62 +105,6 @@ export const schema: Collection_Serialized[] = [
|
||||
deleteRule: null,
|
||||
options: {},
|
||||
},
|
||||
{
|
||||
id: 'systemprofiles0',
|
||||
name: 'users',
|
||||
type: 'auth',
|
||||
system: false,
|
||||
schema: [
|
||||
{
|
||||
id: 'pbfieldname',
|
||||
name: 'name',
|
||||
type: 'text',
|
||||
system: false,
|
||||
required: false,
|
||||
unique: false,
|
||||
options: {
|
||||
min: null,
|
||||
max: null,
|
||||
pattern: '',
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'pbfieldavatar',
|
||||
name: 'avatar',
|
||||
type: 'file',
|
||||
system: false,
|
||||
required: false,
|
||||
unique: false,
|
||||
options: {
|
||||
maxSelect: 1,
|
||||
maxSize: 5242880,
|
||||
mimeTypes: [
|
||||
'image/jpg',
|
||||
'image/jpeg',
|
||||
'image/png',
|
||||
'image/svg+xml',
|
||||
'image/gif',
|
||||
],
|
||||
thumbs: null,
|
||||
},
|
||||
},
|
||||
],
|
||||
listRule: 'id = @request.auth.id',
|
||||
viewRule: 'id = @request.auth.id',
|
||||
createRule: '',
|
||||
updateRule: 'id = @request.auth.id',
|
||||
deleteRule: null,
|
||||
options: {
|
||||
allowEmailAuth: true,
|
||||
allowOAuth2Auth: true,
|
||||
allowUsernameAuth: false,
|
||||
exceptEmailDomains: null,
|
||||
manageRule: null,
|
||||
minPasswordLength: 8,
|
||||
onlyEmailDomains: null,
|
||||
requireEmail: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'aiw8te7y7atklwn',
|
||||
name: 'invocations',
|
||||
@ -251,7 +195,7 @@ export const schema: Collection_Serialized[] = [
|
||||
unique: false,
|
||||
options: {
|
||||
maxSelect: 1,
|
||||
collectionId: 'systemprofiles0',
|
||||
collectionId: '_pb_users_auth_',
|
||||
cascadeDelete: false,
|
||||
},
|
||||
},
|
||||
@ -409,3 +353,5 @@ export const schema: Collection_Serialized[] = [
|
||||
options: {},
|
||||
},
|
||||
]
|
||||
|
||||
console.log(JSON.stringify(schema))
|
||||
|
@ -30,7 +30,6 @@ global.EventSource = require('eventsource')
|
||||
await new Promise<void>((resolve) => {
|
||||
exec(`pkill -f 'pocketbase serve'`, (error, stdout, stderr) => {
|
||||
if (error && error.signal !== 'SIGTERM') {
|
||||
console.log({ error, stderr, stdout })
|
||||
warn(`pkill failed with ${error}: ${stderr}`)
|
||||
}
|
||||
resolve()
|
||||
|
@ -35,13 +35,20 @@ export const createPbClient = (url: string) => {
|
||||
|
||||
const createFirstAdmin = safeCatch(
|
||||
`createFirstAdmin`,
|
||||
(email: string, password: string) => client.admins.create(email, password)
|
||||
(email: string, password: string) =>
|
||||
client.admins
|
||||
.create({ email, password, passwordConfirm: password })
|
||||
.catch((res) => {
|
||||
console.log({ email, password })
|
||||
console.log(JSON.stringify(res, null, 2))
|
||||
return res
|
||||
})
|
||||
)
|
||||
|
||||
const applySchema = safeCatch(
|
||||
`applySchema`,
|
||||
async (collections: Collection_Serialized[]) => {
|
||||
await client.collections.import(collections as Collection[])
|
||||
await client.collections.import(collections as Collection[], false)
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -14,21 +14,32 @@ export const clientService = mkSingleton(async (url: string) => {
|
||||
const client = createPbClient(url)
|
||||
|
||||
try {
|
||||
await client.applySchema(schema)
|
||||
|
||||
await client.adminAuthViaEmail(DAEMON_PB_USERNAME, DAEMON_PB_PASSWORD)
|
||||
dbg(`Logged in`)
|
||||
} catch (e) {
|
||||
dbg(`Creating first admin account`)
|
||||
|
||||
try {
|
||||
await client.createFirstAdmin(DAEMON_PB_USERNAME, DAEMON_PB_PASSWORD)
|
||||
await client.adminAuthViaEmail(DAEMON_PB_USERNAME, DAEMON_PB_PASSWORD)
|
||||
dbg(`Logged in`)
|
||||
} catch (e) {
|
||||
error(
|
||||
`***WARNING*** CANNOT AUTHENTICATE TO ${PUBLIC_APP_PROTOCOL}://${PUBLIC_APP_DB}.${PUBLIC_APP_DOMAIN}/_/`
|
||||
`CANNOT AUTHENTICATE TO ${PUBLIC_APP_PROTOCOL}://${PUBLIC_APP_DB}.${PUBLIC_APP_DOMAIN}/_/`
|
||||
)
|
||||
process.exit(-1)
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
dbg(`Applying schema`)
|
||||
await client.applySchema(schema)
|
||||
dbg(`Schema applied`)
|
||||
} catch (e) {
|
||||
error(`Failed to apply base migration schema`)
|
||||
process.exit(-1)
|
||||
}
|
||||
|
||||
return {
|
||||
client,
|
||||
shutdown() {
|
||||
|
@ -86,9 +86,12 @@ The entire pockethost.io stack can be run locally.
|
||||
git clone git@github.com:benallfree/pockethost.git
|
||||
cd pockethost
|
||||
yarn
|
||||
cp .env-template .env # modify as needed
|
||||
cp .env-template .env # modify as needed, if you used `pockethost.test` for your local domain, everything should work
|
||||
scripts/dev.sh
|
||||
open https://pockethost.test
|
||||
open https://pockethost-central.pockethost.test
|
||||
# login: admin@pockethost.test (change in .env)
|
||||
# password: admin@pockethost.test (change in .env)
|
||||
```
|
||||
|
||||
# Production Deployment
|
||||
|
Loading…
x
Reference in New Issue
Block a user