Skip to content

fix: 301-redirect extensionless directory URLs to add trailing slash (#44) - #45

Merged
jkas2016 merged 5 commits into
mainfrom
fix/44-cloudfront-directory-redirect
Jul 4, 2026
Merged

fix: 301-redirect extensionless directory URLs to add trailing slash (#44)#45
jkas2016 merged 5 commits into
mainfrom
fix/44-cloudfront-directory-redirect

Conversation

@jkas2016

@jkas2016 jkas2016 commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Summary

cloudfront 모드로 배포한 폴더(멀티파일) 문서는 공유 링크에서 trailing slash가 빠지면 콘솔 에러 없는 흰 화면이 됐다. CloudFront Function이 /<code>(슬래시 없음)를 내부 rewrite로 /<code>/index.html을 그대로 200 서빙해, 브라우저 주소가 슬래시 없이 남고 index.html의 상대경로 자산 ./assets/...가 도메인 루트로 새어 403이 났다.

이 PR은 infra/index-rewrite.js의 확장자-없음+슬래시-없음 분기를 내부 rewrite → 301 리다이렉트(/<code>/<code>/, 쿼리스트링 보존)로 바꾼다. 정적 호스트의 표준 디렉터리 인덱스 동작이며, 최상위·중첩 경로에 균일하게 적용된다. 분기 순서(/_*→403, 트레일링 슬래시→index.html, 확장자 없음→301, 파일→통과)와 _meta 403 보호는 그대로다. s3-website 모드는 S3 네이티브 302 리다이렉트로 이미 정상이라 손대지 않았다.

Fixes #44

포함된 부수 변경 (Windows CI 녹색화)

main 기준에서 전체 스위트가 Windows에서 3건 실패(#44와 무관한 기존 이슈)라, 스위트를 녹색으로 되돌리기 위해 아래 2개 커밋을 cherry-pick했다(feat/41-self-hosted-mode에도 존재):

  • .gitattributes*.mjs text eol=lf + skill 테스트 CRLF 허용 — .mjs shebang이 CRLF일 때 나는 SyntaxError 해결
  • npm pack 호출을 execFileSyncexecSync로 — Windows에서 npm.cmd 미해결(ENOENT) 해결

Test plan

  • npx vitest run test/index-rewrite.test.ts — 11 passed (redirect 2 + 쿼리스트링 4 + 회귀 5)
  • npm test — 217 passed / 3 skipped (전체 무회귀)
  • npm run typecheck — 에러 없음
  • npm run builddist/ 생성 성공

배포 주의사항

이 함수 수정은 코드만으로 기존 배포된 CloudFront distribution에 반영되지 않는다. 사용자가 최신 hostdoc으로 재-provision(terraform apply) 해야 새 함수가 적용된다.

🤖 Generated with Claude Code

jkas2016 and others added 5 commits July 5, 2026 01:15
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
On a Windows checkout (core.autocrlf=true, no .gitattributes) the shebang
.mjs wrapper scripts get CRLF line endings. esbuild/vite's hashbang
stripping then leaves an invalid token, so importing them from
test/skill.test.ts fails the whole suite with "SyntaxError: Invalid or
unexpected token" (CI on Linux is LF, so it never saw this). A CRLF shebang
also breaks execution on Unix. Add `*.mjs text eol=lf` so these scripts are
always LF regardless of the contributor's autocrlf.

Once the suite collected, a second latent CRLF assumption surfaced: the
SKILL.md frontmatter regex hard-coded `\n`, so it failed on the CRLF
checkout. Make it line-ending agnostic (`\r?\n`).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
test/pack.test.ts spawned npm with execFileSync("npm", [...]), which throws
spawnSync ENOENT on Windows (the launcher is npm.cmd, and execFileSync does
not apply PATHEXT). Spawning npm.cmd directly is EINVAL since Node's
CVE-2024-27980 fix, and shell:true with an args array warns DEP0190. Use
execSync with a fixed literal command string: the shell resolves npm.cmd on
Windows and /bin/sh runs it on Linux/CI, with no deprecation noise.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jkas2016
jkas2016 merged commit 50b2cd4 into main Jul 4, 2026
3 checks passed
@jkas2016
jkas2016 deleted the fix/44-cloudfront-directory-redirect branch July 4, 2026 18:57
github-actions Bot pushed a commit that referenced this pull request Jul 4, 2026
## [1.2.1](v1.2.0...v1.2.1) (2026-07-04)

### Bug Fixes

* 301-redirect extensionless directory URLs to add trailing slash ([#44](#44)) ([#45](#45)) ([50b2cd4](50b2cd4))
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 1.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] 폴더 배포 시 trailing slash 없는 URL 흰 화면 — 엣지가 /<code> → /<code>/ 리다이렉트 안 함

1 participant