mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Dynamic Astro routes were reading Netlify redirect config through a cwd-relative path, which is fragile inside a serverless runtime and was taking detail pages down with 500s before render. Resolve netlify.toml by searching from the module directory and current working directory, and fail open in request-time redirect lookup so a config read problem does not block page rendering. Constraint: Netlify serverless cwd is not guaranteed to be the repo root Rejected: Inline redirects into route modules | would duplicate platform config and drift from source of truth Rejected: Leave redirect lookup hard-failing | one config read failure should not take down unrelated pages Confidence: medium Scope-risk: narrow Reversibility: clean Directive: Keep redirect config lookup independent of process cwd anywhere server code reads deploy config files Tested: vitest ./test/prebuild/config-node.test.js; pnpm run netlify-build Not-tested: live Netlify production deploy before push
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
import fs from 'fs-extra'
|
|
import os from 'os'
|
|
import path from 'path'
|
|
import { afterEach, describe, expect, it } from 'vitest'
|
|
|
|
import {
|
|
getNetlifyConfigPath,
|
|
getNetlifyRedirect
|
|
} from '~/helpers/config-node.js'
|
|
|
|
const originalCwd = process.cwd()
|
|
|
|
afterEach(() => {
|
|
process.chdir( originalCwd )
|
|
})
|
|
|
|
describe( 'netlify config helpers', () => {
|
|
it( 'resolves netlify.toml even when cwd is outside the repo root', async () => {
|
|
const tempDirectory = await fs.mkdtemp( path.join( os.tmpdir(), 'doesitarm-netlify-' ) )
|
|
|
|
process.chdir( tempDirectory )
|
|
|
|
const configPath = await getNetlifyConfigPath()
|
|
|
|
expect( configPath ).toBe( path.join( originalCwd, 'netlify.toml' ) )
|
|
})
|
|
|
|
it( 'loads redirects when cwd is outside the repo root', async () => {
|
|
const tempDirectory = await fs.mkdtemp( path.join( os.tmpdir(), 'doesitarm-netlify-' ) )
|
|
|
|
process.chdir( tempDirectory )
|
|
|
|
const redirect = await getNetlifyRedirect( '/app/electron' )
|
|
|
|
expect( redirect ).toMatchObject({
|
|
from: '/app/electron',
|
|
to: '/app/electron-framework',
|
|
status: 301
|
|
})
|
|
})
|
|
})
|