https://github.com/hugh888888/vercelkoa2template
A template that can deploy koa2 on vercel, supports connecting to redis and mongodb, no server required, and uses vercel to build backend interface services for free
https://github.com/hugh888888/vercelkoa2template
koa2 mongodb nodejs nodejs-server redis vercel
Last synced: 4 months ago
JSON representation
A template that can deploy koa2 on vercel, supports connecting to redis and mongodb, no server required, and uses vercel to build backend interface services for free
- Host: GitHub
- URL: https://github.com/hugh888888/vercelkoa2template
- Owner: hugh888888
- License: gpl-3.0
- Created: 2024-08-16T02:51:36.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-08-16T10:17:44.000Z (almost 2 years ago)
- Last Synced: 2025-02-02T06:31:41.839Z (over 1 year ago)
- Topics: koa2, mongodb, nodejs, nodejs-server, redis, vercel
- Language: JavaScript
- Homepage: https://template.li-h.me
- Size: 194 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
Vercel Koa2 Template
一个可以在vercel上部署koa2的模板,支持连接redis和mongodb,免费使用vercel搭建后端接口服务,无需服务器
## 🌈 特点
- 🚀 快速部署,无需服务器 [](https://vercel.com/new/clone?repository-url=https%3A//github.com/hugh888888/VercelKoa2Template&env=redis_url&env=mongodbUrl)
- ✈️ 支持连接 redis 和 mongodb
- ✨ 支持配置自定义域名
## 👋 部署教程
### 准备工作
- 域名(可选) 国内推荐使用自定义域名,可托管 CLoudflare,国外使用 vercel 自带域名即可
- [mongodb(可选)](https://www.mongodb.com) mongodb 数据库
- [redis(可选)](https://upstash.com/) redis 数据库
- [Vercel](https://vercel.com)注册 Vercel 账号,用于部署 Koa2 服务
- vercel mongodb redis 可使用 github 账号注册登录,使用个人免费计划

- 
- 
### 部署
**环境变量:**
| 变量名 | 说明 | 示例 |
| ---------- | ------------------ | ---------------------------------------------------------------------------------------------- |
| redis_url | redis 数据库 Url | `redis://default:xxxxx@xxxxxxxx.upstash.io:34903` |
| mongodbUrl | mongodb 数据库 url | `mongodb+srv://:@xxxx.ulopy3w.mongodb.net/?retryWrites=true&w=majority` |
**Vercel:**
推荐使用一键部署按钮(此操作会在你的 github 账户中自动创建仓库并关联部署到 vercel):
[](https://vercel.com/new/clone?repository-url=https%3A//github.com/hugh888888/VercelKoa2Template&env=redis_url&env=mongodbUrl)
## 🔨 本地运行调试
- 1、vercel 上部署本项目,填写环境变量。
- 2、拉取代码到本地,执行以下命令
```bash
# 安装 vercel cli
pnpm i -g vercel
# 获取环境变量
vercel pull --environment=development
# 进入项目目录,安装依赖
pnpm install
# 使用vercel dev启动项目
vercel dev
```
## 🪡 接口 demo
- [getRedisData](https://template.li-h.me/getRedisData) https://template.li-h.me/getRedisData
- [addUser](https://template.li-h.me/addUser?name=1&phone=2) https://template.li-h.me/addUser
- [getList](https://template.li-h.me/getList) https://template.li-h.me/getList
## Star History
[](https://star-history.com/#hugh888888/VercelKoa2Template&Date)