[PIE-14] More robust API proxy #7

Merged
breadone merged 2 commits from PIE-14 into main 2025-08-13 17:54:46 +12:00
3 changed files with 10 additions and 3 deletions
Showing only changes of commit 24e8c23291 - Show all commits

View File

@ -5,7 +5,7 @@ import TagRow from "./TagRow.astro"
const { recipe } = Astro.props; const { recipe } = Astro.props;
const headerImage = await client.collection("images").getOne(recipe.images[0]) const headerImage = await client.collection("images").getOne(recipe.images[0])
const image = await client.files.getURL(headerImage, headerImage.image) const image = await client.files.getRelativeURL(headerImage, headerImage.image)
--- ---
<div class="relative z-0 flex h-50"> <div class="relative z-0 flex h-50">

View File

@ -4,7 +4,7 @@ const { class: className, recipe } = Astro.props
async function getLink(img: string) { async function getLink(img: string) {
const record = await client.collection("images").getOne(img) const record = await client.collection("images").getOne(img)
const link = await client.files.getURL(record, record.image) const link = await client.files.getRelativeURL(record, record.image)
return link return link
} }

View File

@ -1,5 +1,12 @@
import Pocketbase from "pocketbase" import Pocketbase from "pocketbase"
const client = new Pocketbase(import.meta.env.PUBLIC_URL) const client = new Pocketbase("http://localhost:4321")
client.autoCancellation(false) client.autoCancellation(false)
// Return a relative url for file instead of full path including localhost, which breaks external access
client.files.getRelativeURL = (record: { [key: string]: any; }, filename: string, queryParams?: FileOptions | undefined) => {
const res = client.files.getURL(record, filename)
return res.substring(21)
}
export default client; export default client;