0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Next.jsのproxy(middleware)が動作しない!の解決策

Posted at

Next.jsでBasic認証を付けようとしたところ、参考記事どおりに実装しても認証が発火せずハマったので、その原因と解決策のメモです。

結論

appディレクトリがsrc配下にあるのであれば、proxy.ts(またはmiddleware.ts)もsrc内に入れる

proxy.tsの正しい場所

root/
  app/...
  proxy.ts        ← ✅

または

root/
  src/
    app/...
    proxy.ts      ← ✅

ダメなパターン

root/
  src/
    app/...
  proxy.ts        ← ❌

終わりに

バイブコーディングで、AIに実装させてるとこういった初歩的なところで地味にハマりがちですよね。
ついコードがおかしいと思って色々調べてましたが、結局ファイルの位置という。。。

同じようなことで時間を食われている方の参考になれば🙇🏻‍♂️

参考

redditにも同じことしてる人いた。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?