惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
SegmentFault 最新的问题
爱范儿
爱范儿
博客园 - 三生石上(FineUI控件)
Microsoft Security Blog
Microsoft Security Blog
Google DeepMind News
Google DeepMind News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
GbyAI
GbyAI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
V2EX
酷 壳 – CoolShell
酷 壳 – CoolShell
量子位
博客园_首页
T
Tailwind CSS Blog
aimingoo的专栏
aimingoo的专栏
A
About on SuperTechFans
T
The Blog of Author Tim Ferriss
Stack Overflow Blog
Stack Overflow Blog
Recent Announcements
Recent Announcements
P
Proofpoint News Feed
博客园 - 司徒正美
有赞技术团队
有赞技术团队
Engineering at Meta
Engineering at Meta
Last Week in AI
Last Week in AI
MongoDB | Blog
MongoDB | Blog

博客园 - sekihin

【SQLSERVER】备份还原除当前数据库~之外的其他数据库的bak备份 【前端】常用VsCode插件 React席哪个能优化 20 GitHub 仓库帮助你成为 React专家 Error occurred prerendering page "/_not-found".(Next.js 15) Error: Attempted to call generateViewport() from the server (Next.js 15) [cause]: TypeError: e_.createContext is not a function (Next.js 15) Cursor - AI代码编辑器的使用指南 Next.js项目中.prettierrc.json的配置 Next.js项目中.eslintrc.js的配置 nvm: Node Version Manager PHP slim 部署Apache NestJS 部署Apache NestJS导出API文档 ChatGPT plugins Obisidian plugins Build nest.js by tsconfig.json Data Transfer Objects (DTOs) in NestJS TypeError: stringWidth is not a function
Export a named export for each HTTP method instead.(Next....
sekihin · 2025-01-05 · via 博客园 - sekihin

# Next.js 14

// src/app/api/product/route.ts
import prisma from '@/prisma/prisma'
import type { NextApiRequest, NextApiResponse } from 'next'

// GET /api/product
export default async function handle(req: NextApiRequest, res: NextApiResponse) {
  if (req.method === 'GET') {
    try {
      const result = await prisma.products.findMany()
      res.status(200).json(result)
    } catch (error) {
      res.status(500).json({ error: 'Failed to fetch products' })
    }
  } else {
    res.setHeader('Allow', ['GET'])
    res.status(405).end(`Method ${req.method} Not Allowed`)
  }
}

# Next.js 15

import prisma from '@/prisma/prisma'
import type { NextApiRequest, NextApiResponse } from 'next'

export const GET = async (req: NextApiRequest, res: NextApiResponse) => {
  try {
    const result = await prisma.product.findMany();
    res.status(200).json(result);
  } catch (error) {
    res.status(500).json({ error: 'Failed to fetch products' });
  }
};