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 not-found responses for draft galleries

Timothy Yin7e46f9218b9c
diff --git a/apps/site/app/error.vue b/apps/site/app/error.vue
index 48f2185c..b9397225 100644
--- a/apps/site/app/error.vue
+++ b/apps/site/app/error.vue
@@ -12,7 +12,13 @@ useHead({
<h1>
{{ error.statusCode === 404 ? 'Page not found' : 'Service unavailable' }}
</h1>
- <p>Please try again later.</p>
+ <p>
+ {{
+ error.statusCode === 404
+ ? 'This page is unavailable or the gallery has not been published.'
+ : 'Please try again later.'
+ }}
+ </p>
</main>
</template>
<style scoped>
diff --git a/apps/site/server/middleware/00-domain-routing.ts b/apps/site/server/middleware/00-domain-routing.ts
index c1988811..e75e9332 100644
--- a/apps/site/server/middleware/00-domain-routing.ts
+++ b/apps/site/server/middleware/00-domain-routing.ts
@@ -20,6 +20,9 @@ export default defineEventHandler(async (event) => {
})
}
if (
+ // Nuxt renders errors through an internal request without Worker bindings.
+ // Let its renderer preserve the original status instead of resolving the Site again.
+ normalizedPath === '/__nuxt_error' ||
normalizedPath === '/api' ||
normalizedPath.startsWith('/api/') ||
path.startsWith('/_nuxt/')
diff --git a/tests/site-domain-error.test.ts b/tests/site-domain-error.test.ts
new file mode 100644
index 00000000..4d78742a
--- /dev/null
+++ b/tests/site-domain-error.test.ts
@@ -0,0 +1,70 @@
+import assert from 'node:assert/strict'
+import test from 'node:test'
+import { readFileSync } from 'node:fs'
+import vm from 'node:vm'
+import ts from 'typescript'
+
+test('Site domain middleware leaves Nuxt error rendering independent of unavailable Worker bindings', async () => {
+ const exports: Record<string, any> = {}
+ let lookups = 0
+ const missing = Object.assign(new Error('Site not found'), {
+ statusCode: 404,
+ })
+ const code = ts.transpileModule(
+ readFileSync('apps/site/server/middleware/00-domain-routing.ts', 'utf8'),
+ { compilerOptions: { module: ts.ModuleKind.CommonJS } },
+ ).outputText
+ vm.runInNewContext(code, {
+ exports,
+ defineEventHandler: (fn: unknown) => fn,
+ useRuntimeConfig: () => ({ public: { siteBaseDomain: 'chronoframe.art' } }),
+ require: (name: string) => {
+ if (name === 'h3')
+ return {
+ getRequestURL: (e: any) => new URL(e.url),
+ setResponseHeader: (e: any, key: string, value: string) => {
+ e.headers[key] = value
+ },
+ createError: (e: any) => Object.assign(new Error(e.statusMessage), e),
+ }
+ if (name === '@chronoframe/contracts/domains')
+ return { validSiteSlug: () => true }
+ if (name.endsWith('/runtime'))
+ return {
+ platformRequestURL: (e: any) => new URL(e.url),
+ platformDatabase: () => {
+ throw new Error('Database must not be read during error rendering')
+ },
+ }
+ if (name.endsWith('/context'))
+ return {
+ publicSiteContext: async () => {
+ lookups++
+ throw missing
+ },
+ }
+ throw new Error(name)
+ },
+ })
+ await assert.rejects(
+ () =>
+ exports.default({
+ url: 'https://le0.chronoframe.art/',
+ headers: {},
+ method: 'GET',
+ }),
+ { statusCode: 404 },
+ )
+ const event = {
+ url: 'http://localhost/__nuxt_error?error=true&statusCode=404',
+ headers: {} as Record<string, string>,
+ method: 'GET',
+ }
+ await exports.default(event)
+ assert.equal(
+ lookups,
+ 1,
+ 'the error render must not attempt another tenant lookup',
+ )
+ assert.equal(event.headers['Cache-Control'], 'no-store')
+})