Production URLs: recommend URL_PORT=:443, strip default ports
A missing URL_PORT defaults to :8080, and deploy panels often can't store an empty value, so production kept ORIGIN=https://admin.<domain>:8080 and the admin login still failed with "Cross-site POST form submissions are forbidden" (reproduced against production). URL_PORT=:443 is non-empty and adapter-node normalises it away (new URL().origin). The PUBLIC_* URLs are used verbatim in saved image URLs, email links and the admin's View link, so they now go through baseUrl(), which drops default ports and trailing slashes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KgF3Kf47LjPGHKQHszpUAv
This commit is contained in:
parent
7b6c8c2511
commit
bf4c619074
10 changed files with 34 additions and 13 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { env } from '$env/dynamic/public';
|
||||
import { error, json } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from './$types';
|
||||
import { pbUrl } from '$lib/pb';
|
||||
import {
|
||||
dataUriToFile,
|
||||
restorePlaceholders,
|
||||
|
|
@ -41,7 +41,7 @@ export const POST: RequestHandler = async ({ request, locals }) => {
|
|||
formData.append('alt', filename.replace(/\.[^/.]+$/, '').replace(/[-_]/g, ' '));
|
||||
|
||||
const record = await locals.pb.collection('media').create(formData);
|
||||
const publicUrl = env.PUBLIC_POCKETBASE_URL;
|
||||
const publicUrl = pbUrl;
|
||||
const newUrl = `${publicUrl}/api/files/${record.collectionId}/${record.id}/${record.file}`;
|
||||
|
||||
keyToUrl.set(key, newUrl);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { env } from '$env/dynamic/public';
|
||||
import { error, json } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from './$types';
|
||||
import { pbUrl } from '$lib/pb';
|
||||
|
||||
export const POST: RequestHandler = async ({ request, locals }) => {
|
||||
const formData = await request.formData();
|
||||
|
|
@ -17,7 +17,7 @@ export const POST: RequestHandler = async ({ request, locals }) => {
|
|||
|
||||
try {
|
||||
const record = await locals.pb.collection('media').create(uploadForm);
|
||||
const publicUrl = env.PUBLIC_POCKETBASE_URL;
|
||||
const publicUrl = pbUrl;
|
||||
const url = `${publicUrl}/api/files/${record.collectionId}/${record.id}/${record.file}`;
|
||||
return json({ record, url });
|
||||
} catch (e) {
|
||||
|
|
|
|||
|
|
@ -2,11 +2,12 @@
|
|||
import { env } from '$env/dynamic/public';
|
||||
import { confirmSubmit } from '$lib/admin/confirm';
|
||||
import Modal from '$lib/admin/Modal.svelte';
|
||||
import { baseUrl } from '$shared/url';
|
||||
|
||||
let { data, form } = $props();
|
||||
let showCreate = $state(false);
|
||||
|
||||
const siteUrl = (env.PUBLIC_SITE_URL || '').replace(/\/$/, '');
|
||||
const siteUrl = baseUrl(env.PUBLIC_SITE_URL);
|
||||
const publicUrl = (slug: string) => `${siteUrl}/${slug === 'home' ? '' : slug}`;
|
||||
</script>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue