在Next.js中使用Golang编写路由是可能的吗?

huangapple go评论76阅读模式
英文:

Is it possible to write a route in NextJS using Golang?

问题

在Next.js中使用Golang编写路由是可能的吗?

就像文件夹结构如下:

  • pages

    • api

      • name.go

然后我们可以查询/api/name并获得响应吗?

英文:

is it possible to write a route in NextJS using Golang?

Like the folder structure would be:

  • pages

    • api

      • name.go

And we can query /api/name and get a response back?

答案1

得分: 0

这是NextJS不提供的功能。但是如果你将页面托管在Vercel上,你可以使用他们的无服务器函数的Go运行时来实现相同的功能。

你可以通过将文件路径设置为/api/name.go而不是/pages/api/name.go来实现这一点。

英文:

This is not something NextJS provides. But if you are hosting your page on Vercel, you can use their Go Runtime for Serverless Functions to achieve the same thing.

You can do this by having the file path be /api/name.go instead of /pages/api/name.go.

huangapple
  • 本文由 发表于 2023年1月14日 14:36:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75116234.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定