localhost:300/api is not working : “This page isn’t working“

题意:运行 azure api 时遇到的错误提示。

问题背景:

When I ran npm run dev in the console, the web site runs but when I tried to run the API, its not working, I have created a portfolio folder: app: [api: route.js] , page.js.

当我在控制台运行 npm run dev 时,网站可以运行,但当我尝试运行 API 时,它不起作用。我已经创建了一个名为 portfolio 的文件夹,其中包含:app(其中包含 api: route.js 和 page.js

route.js:

import { OpenAIClient, AzureKeyCredential } from '@azure/openai';
import { NextResponse } from 'next/server';

const endpoint = process.env.AZURE_OPENAI_ENDPOINT;
const apiKey = process.env.AZURE_OPENAI_API_KEY;
const model = process.env.AZURE_OPENAI_MODEL;

export async function POST(req){
    

    return NextResponse.json({ 
        message: 'Hello world'
     })
}

.env:

AZURE_OPENAI_ENDPOINT=https://******.openai.azure.com/
AZURE_OPENAI_API_KEY=**************
AZURE_OPENAI_MODEL=deployment

results :
should be the screen which shows :
{
        Hello World
}

Here i tried to run the npm run dev , then i typed in the url : localhost:300/api then i faced the issue : "This page isn’t working"

我尝试运行 npm run dev,然后我在 URL 栏中输入了 localhost:300/api,但我遇到了问题:“此页面无法正常工作”。

问题解决:

You've defined a POST route, but you're trying to access it with a GET request. Either send a POST request, or change your route to a GET route:

你已经定义了一个 POST 路由,但你却试图使用 GET 请求来访问它。要么发送一个 POST 请求,要么将你的路由更改为 GET 路由:

export async function GET(req) {
    return NextResponse.json({ 
        message: 'Hello world'
     });
}

  • 7
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

营赢盈英

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值