実現したいこと
spabaseのデータをprismaとnextjsを使ってjson形式で抽出したい。
発生している問題・分からないこと
react
1import BBSCardList from "./components/BBSCardList"; 2 3export default async function Home() { 4 const response = await fetch("http://localhost:3000/api/post", { 5 cache: "no-store", 6 }); 7 8 const bbsAllData = await response.json(); 9 10 return ( 11 <main> 12 <BBSCardList /> 13 </main> 14 ); 15} 16
上記のコードを実行するとエラーが出ます。
エラーメッセージ
error
1Unhandled Runtime Error 2Error: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
該当のソースコード
react
1import BBSCardList from "./components/BBSCardList"; 2 3export default async function Home() { 4 const response = await fetch("http://localhost:3000/api/post", { 5 cache: "no-store", 6 }); 7 8 const bbsAllData = await response.json(); 9 10 return ( 11 <main> 12 <BBSCardList /> 13 </main> 14 ); 15} 16
特になし
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
console.log(response);
をすると以下が表示されます
Response {
[Symbol(realm)]: null,
[Symbol(state)]: {
aborted: false,
rangeRequested: false,
timingAllowPassed: true,
requestIncludesCredentials: true,
type: 'default',
status: 404,
timingInfo: {
startTime: 8651.757667,
redirectStartTime: 0,
redirectEndTime: 0,
postRedirectStartTime: 8651.757667,
finalServiceWorkerStartTime: 0,
finalNetworkResponseStartTime: 0,
finalNetworkRequestStartTime: 0,
endTime: 0,
encodedBodySize: 0,
decodedBodySize: 0,
finalConnectionTimingInfo: null
},
cacheState: '',
statusText: 'Not Found',
headersList: HeadersList {
cookies: null,
[Symbol(headers map)]: [Map],
[Symbol(headers map sorted)]: null
},
urlList: [ URL {} ],
body: { stream: undefined, length: undefined, source: undefined }
},
[Symbol(headers)]: HeadersList {
cookies: null,
[Symbol(headers map)]: Map(9) {
'cache-control' => [Object],
'vary' => [Object],
'x-powered-by' => [Object],
'content-type' => [Object],
'content-encoding' => [Object],
'date' => [Object],
'connection' => [Object],
'keep-alive' => [Object],
'transfer-encoding' => [Object]
},
[Symbol(headers map sorted)]: null
}
}
✓ Compiled /favicon.ico in 45ms (297 modules)
const bbsAllData = await response.json(); の部分で、json形式で返ってきていないからエラーなのかな?と思ったりするのですが、原因が特定できません。画像を添付します。
どうぞよろしくお願いします。
補足
特になし

回答2件
あなたの回答
tips
プレビュー