Home  >  Article  >  Backend Development  >  Is it possible to write routes in NextJS using Golang?

Is it possible to write routes in NextJS using Golang?

王林
王林forward
2024-02-12 11:45:09556browse

是否可以使用 Golang 在 NextJS 中编写路由?

php editor Yuzai answers your question: Is it possible to use Golang to write routes in NextJS? The answer is no. NextJS is a server rendering framework based on React, which uses JavaScript language. Golang is a compiled language with different syntax and features from JavaScript. Although you can use Golang to write back-end interfaces or services in NextJS, in NextJS routing, you still need to use JavaScript to define and process routes. Therefore, if you want to write routes in NextJS, it is recommended to use JavaScript or TypeScript to achieve it.

Question content

Is it possible to use Golang to write routes in NextJS?

Just like the folder structure:

  • page

    • API

      • name.go

Can we query /api/name and get a response?

Solution

This is not provided by NextJS. However, if you host your page on Vercel, you can achieve the same effect using their Go runtime serverless functions.

You can achieve this by setting the file path to /api/name.go instead of /pages/api/name.go.

The above is the detailed content of Is it possible to write routes in NextJS using Golang?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete