git: 원격 저장소 연결 및 초기 커밋
Made-with: Cursor
This commit is contained in:
13
src/lib/apiUrl.js
Normal file
13
src/lib/apiUrl.js
Normal file
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* API·정적 자원용 베이스 URL과 경로를 결합한다. 끝 슬래시는 정규화한다.
|
||||
* @param {string | undefined} base
|
||||
* @param {string} [path]
|
||||
* @returns {string}
|
||||
*/
|
||||
export function toApiUrl(base, path = '') {
|
||||
if (!base) return ''
|
||||
const trimmed = base.replace(/\/+$/, '')
|
||||
if (!path) return trimmed
|
||||
const normalized = path.startsWith('/') ? path : `/${path}`
|
||||
return `${trimmed}${normalized}`
|
||||
}
|
||||
19
src/lib/pocketBase.js
Normal file
19
src/lib/pocketBase.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import PocketBase from 'pocketbase'
|
||||
import { toApiUrl } from '@/lib/apiUrl'
|
||||
|
||||
/** @type {PocketBase | null} */
|
||||
let client = null
|
||||
|
||||
/**
|
||||
* @returns {PocketBase}
|
||||
*/
|
||||
export function getPocketBase() {
|
||||
const base = import.meta.env.VITE_POCKETBASE_URL
|
||||
if (!base) {
|
||||
throw new Error('VITE_POCKETBASE_URL이 설정되지 않았습니다.')
|
||||
}
|
||||
if (!client) {
|
||||
client = new PocketBase(toApiUrl(base))
|
||||
}
|
||||
return client
|
||||
}
|
||||
13
src/lib/todoSchema.js
Normal file
13
src/lib/todoSchema.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export const todoTitleSchema = z.object({
|
||||
title: z.string().trim().min(1, '제목을 입력하세요.').max(500, '제목이 너무 깁니다.')
|
||||
})
|
||||
|
||||
/**
|
||||
* @param {unknown} input
|
||||
* @returns {{ title: string }}
|
||||
*/
|
||||
export function parseTodoTitle(input) {
|
||||
return todoTitleSchema.parse(input)
|
||||
}
|
||||
Reference in New Issue
Block a user