Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Repeated segments should be supported by passing array to pathToRegExp.compile

オープン
#98 コメント 0 件 リアクション 2 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
javascript
領域
backend

調査の方向性

Start at toTarget in src/index.js around lines 79-86 and compare the path-to-regexp compile documentation with how repeated parameters are assigned. Add coverage for repeated segments in rewrites and redirects, then update the documentation with the required destination pattern and verify the affected tests pass.

索引モデルが issue の本文から書いたものです。

説明

Context
  • Serving react app under /app prefix e.g. example.com/app/products
  • Installed serve and customized with serve.json
  • Used "homepage":"/app" in package.json according to CRA docs
  • Asset path is correctly inferred and generated but serve is not serving asset files correctly under build/static/...

serve.json used for above:

{
  "public": "build",
  "rewrites": [
    { "source": "/app/static/:segment*", "destination": "/static/:segment*" },
    { "source": "/app", "destination": "/index.html"}.
    { "source": "/app/**", "destination": "/index.html"}
  ]
}

After some debugging, I identified the issue to be in toTarget. We are not passing in array of parameters when we are compiling the valid path https://github.com/zeit/serve-handler/blob/e7c4e42a63e9cd59b43256bb4ca04a22a5f77994/src/index.js#L79-L86

We should be passing array according to the docs(v2.2.1 that we are using). If not it treats the whole string as a single segment value and encodes / .

Debug logs:

// applyRewrites
relativePath: "/app/static/css/2.c7bb94bc.chunk.css" //argument
rewrittenPath: "/app/%2Fcss%2F2.c7bb94bc.chunk.css" // return value

// toTarget
props: {
  "segment": "/css/2.c7bb94bc.chunk.css"
}
normalizedDest: "/static/:segment*"
toPath(props): "/static/%2Fcss%2F2.c7bb94bc.chunk.css"

This should be easily fixed by doing a split by / when we are setting the props i.e. props[name] = results[index + 1].split("/");

This will fix repeated segment for redirects as well.

Documents should also be updated with instructions on how to use repeated segment. (I figured out during debugging that destination needs * as well else the compile function will complain that the url built does not match the destination pattern 😅)

Not sure if my proposed solution is correct but it works locally for me so far. I am happy to work on this with tests and docs for repeated segment

主要言語
JavaScript
スター
617
フォーク
119
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

vercel/serve-handler のほかの issue

vercel/serve-handler の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。