Netlify 是一个流行的静态站点托管无服务器平台。它是一种以更具可伸缩性和安全性的方式构建、部署和扩展现代 Web 应用程序的流行方法。
Netlify 帮助开发者在几分钟内轻松启动网站和活动。Netlify 主要为 JAMstack 站点构建,JAMstack 将 JavaScript 和 API 统一起来,创建出既适合开发者也适合内容编辑者的应用程序。
在本教程中,您将看到如何在 5 分钟内将使用 Next.js 和 TailwindCSS 构建的简单 Redis 缓存应用程序部署到 Netlify。
访问 https://redis.ac.cn/try-free 创建免费的 Redis Cloud 账户。在创建 Redis Enterprise Cloud 数据库时启用“RediSearch”模块。您将获得一个数据库终端节点 URL 和密码。保存以备将来参考。
Netlify 的命令行界面 (CLI) 允许您直接从命令行配置持续部署。在您的本地笔记本电脑上运行以下命令安装 Netlify CLI
npm install netlify-cli -g
运行以下命令验证 Netlify 是否已安装
netlify version
netlify-cli/8.15.3 darwin-x64 node-v14.17.3
git clone https://github.com/redis-developer/nextjs-redis-netlify
要使用命令行进行身份验证并获取访问令牌,请运行以下命令登录您的 Netlify 账户
netlify login
这将打开一个浏览器窗口,要求您使用 Netlify 登录并授权访问 Netlify CLI。身份验证成功后,它会要求您关闭窗口并显示以下结果
The netlify init
命令允许您为新站点或现有站点配置持续部署。如果该文件不存在,它也会创建 netlify.toml 文件。
上述步骤会创建一个 netlify.toml
文件,内容如下:
[build]
command = "npm run build"
publish = ".next"
[[plugins]]
package = "@netlify/plugin-nextjs"
按照 Netlify 的指示,运行以下命令将最新更改推送到 GitHub
git add .
git commit -m “Pushing the latest changes”
git push
netlify open --admin
点击“触发部署”部署站点
点击部署 URL,您应该能够按图所示访问应用程序
Already logged in via netlify config on your machine
Run netlify status for account details
To see all available commands run: netlify help
netlify init
? What would you like to do? + Create & configure a new site
? Team: Redis
Choose a unique site name (e.g. super-cool-site-by-redisdeveloper.netlify.app) or leave it blank for a random name. You can update the site name later.
? Site name (optional): undefined
Site Created
Admin URL: https://app.netlify.com/sites/super-cool-site-by-redisdeveloper
URL: https://super-cool-site-by-redisdeveloper.netlify.app
Site ID: a70bcfb7-b7b1-4fdd-be8b-5eb3b5dbd404
Linked to super-cool-site-by-redis-developer in /Users/redisdeveloper/projects/netlify/basic-caching-demo-nodejs/.netlify/state.json
? Your build command (hugo build/yarn run build/etc): yarn start
? Directory to deploy (blank for current dir): dist
? Netlify functions folder: functions
Adding deploy key to repository...
Deploy key added!
Creating Netlify GitHub Notification Hooks...
Netlify Notification Hooks configured!
Success! Netlify CI/CD Configured!
This site is now configured to automatically deploy from github branches & pull requests
Next steps:
git push Push to your git repository to trigger new site builds
netlify open Open the Netlify admin URL of your site