1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Application error: a server-side exception has occurred (see the server logs for more information).エラーでページが表示されない

Posted at

はじめに

next.jsをfirebaseにデプロイしようとした際に、ページが表示されず悩んだので解決策を載せておきます。

事象

next.jsをfirebaseにデプロイしました。
firebase deployでデプロイを行い、特にエラーも表示されなかったためページを見に行ったらこのような画面が表示されていました。

image.png

原因

APIをfetchする処理をこのように入れているのですが、envで指定しているNEXT_PUBLIC_API_URLがhttp://localhost:3000となっているためでした。
実際のfirebaseでhostingしているURLは別なのでローカルのものを指定しても動きません。

const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/qiita`, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ page: 4 }),
});

解決策

NEXT_PUBLIC_API_URLを実際のURLを指定するように書き換えました。

NEXT_PUBLIC_API_URL="実際のURL"

おわりに

ローカルでは動くのに、デプロイしたURLでページがみれないときはAPIが正しいURLとなっているか調べて見るとよさそうです。

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?