我应该如何初始化 Nextjs 9.0 中的一些代码

天野光*_*天野光 5 next.js

使用create-next-app这样创建新项目

\n\n
npx create-next-app next9.1\ncd next9.1\ntree -I node_modules\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 components\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 nav.js\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 next.config.js\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 package.json\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pages\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 index.js\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 static\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 favicon.ico\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 yarn.lock\n
Run Code Online (Sandbox Code Playgroud)\n\n

创造/pages/api/index.ts文件然后客户端可以调用/api

\n\n

但我需要从 mysql 查询一些数据,我应该在哪里和何时在没有 server.js 的情况下初始化 mysql 池(在 nextjs 珍贵版本中)

\n

小智 -1

阅读 Zeit 的以下文章(未更新到 next9,但类似,只需将 api 文件夹移至其中,/pages以便您可以利用动态路由和 ES5+ )

https://zeit.co/guides/deploying-next-and-mysql-with-now