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

Is it possible to write routes in NextJS using Golang?

王林
Release: 2024-02-12 11:45:09
forward
591 people have browsed it

是否可以使用 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!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template