Skip to content

Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.

fix(site): preserve API boundaries before domain routing

Timothy Yin14b81fd06157
diff --git a/apps/site/server/middleware/00-domain-routing.ts b/apps/site/server/middleware/00-domain-routing.ts
index 250ff7e6..c1988811 100644
--- a/apps/site/server/middleware/00-domain-routing.ts
+++ b/apps/site/server/middleware/00-domain-routing.ts
@@ -9,7 +9,22 @@ import { publicSiteContext } from '../../../shared/platform/context'
/** Redirect documents only; cookies and private media remain bound to the requesting Host. */
export default defineEventHandler(async (event) => {
const path = getRequestURL(event).pathname
- if (path === '/api/health' || path.startsWith('/_nuxt/')) return
+ setResponseHeader(event, 'Cache-Control', 'no-store')
+ let normalizedPath: string
+ try {
+ normalizedPath = decodeURIComponent(path).toLowerCase()
+ } catch {
+ throw createError({
+ statusCode: 400,
+ statusMessage: 'Invalid request path',
+ })
+ }
+ if (
+ normalizedPath === '/api' ||
+ normalizedPath.startsWith('/api/') ||
+ path.startsWith('/_nuxt/')
+ )
+ return
const url = platformRequestURL(event),
runtime = useRuntimeConfig(event),
base = runtime.public.siteBaseDomain,
@@ -37,7 +52,6 @@ export default defineEventHandler(async (event) => {
!validSiteSlug(host.slice(0, -base.length - 1))
)
throw createError({ statusCode: 404 })
- if (path.startsWith('/api/')) return
const context = await publicSiteContext(event)
if (!['GET', 'HEAD'].includes(event.method)) return
setResponseHeader(event, 'Cache-Control', 'no-store')
diff --git a/scripts/smoke-edge-entry.mjs b/scripts/smoke-edge-entry.mjs
index 44e2544e..66a47c6a 100644
--- a/scripts/smoke-edge-entry.mjs
+++ b/scripts/smoke-edge-entry.mjs
@@ -127,7 +127,12 @@ try {
}
} else {
assert.equal((await fetch(base + '/albums')).status, 503)
- assert.equal((await fetch(base + '/dashboard')).status, 404)
+ // Administrative redirects require a published Host and configured platform data.
+ for (const path of ['/dashboard', '/admin'])
+ assert.equal(
+ (await fetch(base + path, { redirect: 'manual' })).status,
+ 503,
+ )
}
console.log(
`PASS ${entry}: actual workerd SSR, entry routes, unavailable platform APIs, and Self-hosted session isolation`,