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

推荐订阅源

Last Week in AI
Last Week in AI
D
DataBreaches.Net
腾讯CDC
Recent Announcements
Recent Announcements
有赞技术团队
有赞技术团队
A
About on SuperTechFans
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
云风的 BLOG
云风的 BLOG
罗磊的独立博客
月光博客
月光博客
MyScale Blog
MyScale Blog
U
Unit 42
Martin Fowler
Martin Fowler
Stack Overflow Blog
Stack Overflow Blog
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
N
Netflix TechBlog - Medium
G
Google Developers Blog
博客园 - 【当耐特】
D
Docker
I
InfoQ
雷峰网
雷峰网

博客园 - 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' });
  }
};