通过 cron 定时任务定期调用 Supabase 数据库,避免免费版项目因 7 天无活动被暂停
supabase-pause-prevention — Next.js 企业官网模板
作者 travisvn
用于防止 Supabase 免费版项目因 7 天无活动被暂停的 Next.js 工具模板,通过定时任务调用数据库保持项目活跃。
看看你的网站会是什么样
浏览真实页面截图,比较内容排版与手机效果。点击下方缩略图切换,放大查看整页细节。
全部页面与视图 3
截图用于了解视觉与布局,交互效果请以实际项目为准。
值得关注的模板亮点
从已有项目资料中,快速了解它的特点。
针对 Vercel 免费版仅允许一个 cron job 的限制,用主项目 API 端点转发请求唤醒其他项目
核心改动集中在 keep-alive 路由、辅助函数、配置文件和 vercel.json 四个文件
提供 keep-alive 表的示例 SQL,并支持可选的数据库插入与删除动作
附带使用 Prisma 作为 ORM 的其他项目接入示例,以及 /pages 目录的旧版辅助函数
模板详细介绍
该模板解决 Supabase 免费版项目在超过 7 天无活动后被自动暂停的问题。核心做法是在 Next.js 项目中创建一个 cron 定时任务,定期向 Supabase 数据库发起一次简单查询,使项目保持活跃状态。
由于 Vercel 免费版限制每个账号只能配置一个 cron job,模板还提供了多项目方案:主项目通过 keep-alive API 端点去请求其他 Supabase 项目的 keep-alive 端点,从而让多个项目都被定期唤醒。其他项目只需提供一个可访问且会实际调用数据库的 API 端点,并确保服务端不缓存该响应。
代码结构上,真正需要关注的只有四个文件:/app/api/keep-alive/route.ts(cron 执行的 API 端点)、/app/api/keep-alive/helper.ts(辅助函数)、/config/keep-alive-config.ts(配置)以及 /vercel.json(定时调度配置)。utils/supabase 目录来自 Supabase 官方 Next.js 教程示例,其余为 create-next-app 生成的样板代码。README 建议使用一张 keep-alive 表,并支持可选的插入与删除操作。
需要注意,作者已在 README 中提示有改用 Python 重写的新版本(supabase-inactive-fix 仓库)。本模板基于 Next.js 与 React,采用 MIT 许可,属于免费版本代码;演示图片、字体、图标等第三方素材以及域名、托管、数据库等外部服务需另行核对许可与费用。
适合你的项目吗?
适用场景
- 在 Vercel 上部署的 Supabase 免费版项目需要长期保持活跃
- 同时维护多个 Supabase 免费版项目,希望用单个 cron job 统一保活
- 已有 Next.js + Supabase 项目,想以最小改动加入保活机制
- 使用 Prisma 等 ORM 的其他项目需要接入主项目的保活请求
适合人群
- 使用 Supabase 免费版并部署在 Vercel 上的 Next.js 开发者
- 需要为多个 Supabase 项目做定期活跃检查的个人或小团队
- 希望直接阅读源码并按需裁剪保活逻辑的开发者
上手与定制指南
结合仓库当前版本的说明,按下面的资料检查内容、配置与运行要求。
- 1
复制 /app/api/keep-alive/route.ts、helper.ts、/config/keep-alive-config.ts 与 /vercel.json 到自己的项目
- 2
在 Supabase 中创建 keep-alive 表,可参考 README 提供的 SQL 语句
- 3
为其他需要保活的 Supabase 项目添加可访问的 API 端点,并确保该端点会实际查询数据库且不被服务端缓存
- 4
README 提示已有 Python 重写的新版本,选用前可先确认版本差异
授权与来源资料
使用条件与限制
免费使用 · 保留许可声明本次收录的是公开仓库中采用 MIT 许可的免费版本;免费范围为该版本代码,不代表外部服务或第三方素材免费。
使用时需要遵守
- 允许免费使用、修改、商用和分发该版本代码。
- 分发代码副本或实质性部分时,保留原作者版权声明和完整 MIT 许可声明。
- 代码按现状提供;担保与责任限制以原许可证及适用法律为准。
额外费用与待核对事项
- 该方案针对 Supabase 免费版:项目超过 7 天无活动会被暂停,因此需要定时任务保持活跃;付费版无此限制。
- Vercel 免费版每个账号仅允许一个 cron job,多项目保活需借助主项目 API 端点转发请求。
- 其他 Supabase 项目必须提供可访问且会实际调用数据库的 API 端点,否则无法被保活。
- 保活端点必须禁用服务端缓存,否则缓存响应不会真正触发数据库调用。
- 作者提示已有 Python 重写的新版本仓库,选用本模板前应确认版本差异。
- 演示图片、字体、图标及其他第三方素材需按各自许可核对,不能仅凭代码的 MIT 许可判断。
- 域名、托管、数据库、支付或 AI 等外部服务可能另外收费。
查看原文依据
Permission is hereby granted, free of charge
许可证原文
On the free-tier plan, projects that are inactive for more than 7 days are paused.
README 原文
as Vercel limits free-tier users to one cron job
README 原文
The only requirement is that this endpoint is reachable and makes a call to your Supabase database
README 原文
Ensure the server doesn't cache this
README 原文
https://github.com/travisvn/supabase-pause-prevention/blob/main/LICENSEhttps://github.com/travisvn/supabase-pause-prevention/blob/main/README.md__NEW & IMPROVED VERSION__ written in Python available at [supabase-inactive-fix repo](https://github.com/travisvn/supabase-inactive-fix)
README 原文
DeepSeek 根据仓库许可证和 README 整理 ·2026-10-02。结果仅覆盖已读取资料,依赖、图片、字体及后续条款变更以各自原文为准。
项目核对记录与介绍依据
模板资料
- 来源平台
- GitHub
- 资料与维护参考分
- 资料较完整 · 90 / 100
- 技术栈
- Next.js · React
- 网站类型
- 企业官网
这个分数如何计算
本站按许可资料(最高30分)、演示链接(12分)、预览图(10分)、Star数(15分)、记录的维护时间(15分)、描述完整度(8分)、功能记录(5分)和分类资料(5分)计算。它不是代码、安全或性能测试,也不是 Google 评分;有链接不代表已实测可用。
这个项目需要核对什么
- 记录的仓库更新时间
- 2025-04-01
- 截图检查日期
- 2026-10-02
已收录演示链接。请用你的内容与屏幕尺寸检查;有演示不代表表单、认证或支付已经可用。
目录记录的主要技术栈是 Next.js。请通过依赖清单和锁文件核对实际版本与托管要求。这些说明基于收录资料,不代表代码审计或部署实测。
查看具体选型方法 →介绍的制作与核对状态
介绍由 AI 辅助整理目录与仓库资料。仓库作者不等于这篇介绍的审核者。
已完成服务器许可规则与 AI 来源核对;未经过人工编辑审核。
查看当时使用的来源资料
SHA-256: a8b7e14c3fc0d1188a3236d9516609d8051d177146f03895ac91964b8455c8e3
2026-10-02T09:25:52.453Z
来源文件 / 仓库# Supabase Pause Prevention ⏸️





🛑 Stop Supabase projects from pausing due to inactivity! :raised_hands:
> On the free-tier plan, projects that are inactive for more than 7 days are paused.
# Please star ⭐️ if you find this useful
> [!TIP]
> __NEW & IMPROVED VERSION__ written in Python available at [supabase-inactive-fix repo](https://github.com/travisvn/supabase-inactive-fix)
## Solution / How it works
- Creating a _cron job_ (scheduled task) that makes a simple database call
- _(This keeps your Supabase project active)_
- Fetching `keep-alive.ts` API endpoints for the other projects, as Vercel limits free-tier users to one cron job.
## Getting Started
**Super simple to add to your existing Supabase project!**
### Configure your main project
_Only 3 files matter_
- [`/app/api/keep-alive/route.ts`](app/api/keep-alive/route.ts) - API endpoint the cron job will execute
- [`/app/api/keep-alive/helper.ts`](app/api/keep-alive/helper.ts) - Helper functions called from `route.ts`
- [`/config/keep-alive-config.ts`](config/keep-alive-config.ts) - Configuration for your setup
- [`/vercel.json`](vercel.json) - Directs Vercel to periodically run the `keep-alive` endpoint
`utils/supabase` folder contains files provided in the Supabase docs for the [Next.js Web App demo — Supabase](https://supabase.com/docs/guides/getting-started/tutorials/with-nextjs)
Everything else is boilerplate from Next.js `create-next-app`
### Configuring your other Supabase projects
After selecting your primary project _(the one that implements the code provided in this repository)_, you'll want to add an API endpoint to your other Supabase projects
The only requirement is that this endpoint is reachable and makes a call to your Supabase database
> [!NOTE]
> API endpoint must make database call
> Ensure the server doesn't cache this
<details>
<summary>Example of a setup using Prisma as an ORM</summary>
`/pages/api/keep-alive.ts`
```typescript
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from 'next'
import { prisma } from 'src/server/db'
// See next example for contents of @/utils/helper
import { generateRandomString } from '@/utils/helper'
export default async function handler(
_req: NextApiRequest,
res: NextApiResponse
) {
try {
const randomString = generateRandomString()
const dbResponse = await prisma.keepAlive.findMany({
where: {
name: {
equals: randomString,
}
}
})
const successMessage = (dbResponse != null) ? `Success - found ${dbResponse.length} entries` : "Fail"
res.status(200).json(successMessage)
} catch (e) {
res.status(401).send("There was an error")
}
}
```
`/prisma/schema.prisma`
```prisma
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
previewFeatures = ["postgresqlExtensions"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
extensions = [uuidOssp(map: "uuid-ossp")]
}
model KeepAlive {
id BigInt @id @default(autoincrement())
name String? @default("")
random String? @default(dbgenerated("gen_random_uuid()")) @db.Uuid
}
```
</details>
<details>
<summary>Helper function for '/pages' directory (legacy support)</summary>
`/utils/helper.ts`
```typescript
const defaultRandomStringLength: number = 12
const alphabetOffset: number = 'a'.charCodeAt(0)
export const generateRandomString = (length: number = defaultRandomStringLength) => {
let newString = ''
for (let i = 0; i < length; i++) {
newString += String.fromCharCode(alphabetOffset + Math.floor(Math.random() * 26))
}
return newString
}
```
</details>
### Sample SQL
Any table and column can be called, but if you'd rather go with a generic, here's a SQL query for a `keep-alive` table
```sql
CREATE TABLE "keep-alive" (
id BIGINT generated BY DEFAULT AS IDENTITY,
name text NULL DEFAULT '':: text,
random uuid NULL DEFAULT gen_random_uuid (),
CONSTRAINT "keep-alive_pkey" PRIMARY key (id)
);
INSERT INTO
"keep-alive"(name)
VALUES
('placeholder'),
('example');
```
> [!IMPORTANT]
> It is now **strongly recommended** to use a `keep-alive` table like the one above.
> This is in light of the added features for _optional_ database insertion & deletion actions
___
### Sample response
Visiting `https://your-project-domain.vercel.app/api/keep-alive`
```
Results for retrieving
'mzmgylpviofc' from 'keep-alive' at column 'name': []
Other Endpoint Results:
https://your-other-vercel-project-urls.vercel.app/api/keep-alive - Passed
https://your-other-supabase-app.com/api/keep-alive - Passed
```
<details>
<summary>Extended response (with insertion / deletion)</summary>
```
Results for retrieving entries from 'keep-alive' - 'name column: [{"name":"placeholder"},{"name":"random"}, ... ,{"name":"uujyzdnsbrgi"}]
Results for deleting
'uujyzdnsbrgi' from 'keep-alive' at column 'name': success
```
</details>
___
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
看看同类模板
对比同技术栈与用途的模板,找到更适合的视觉与内容结构。

SaaS-Boilerplate
🚀🎉📚 SaaS Boilerplate built with Next.js + Tailwind CSS + Shadcn UI + TypeScript. ⚡️ Full-stack React applic…
Next.js · SaaS

Next-JS-Landing-Page-Starter-Template
🚀 Free NextJS Landing Page Template written in Tailwind CSS 3 and TypeScript ⚡️ Made with developer experienc…
Next.js · 企业官网

next-saas-starter
⚡️ Free Next.js responsive landing page template for SaaS products made using JAMStack architecture.
Next.js · SaaS

startup-nextjs
Startup is free Next.js template for SaaS startups comes with all the essential pages, components, and section…
Next.js · SaaS

shadcn-landing-page
New design 🎉 Nextjs + Shadcn + TypeScript + Tailwind. Landing page template ease-to-use
Next.js · 企业官网

shadcn-dashboard-landing-template
Accelerate your development with a sleek, open-source admin dashboard and landing page built on Vite-React, Ne…
Next.js · 后台
