跳到主要内容

Next.js 集成指南

Anima 提供了针对 Next.js 框架的原生集成方案,让您无需手动管理隧道,开发服务器启动时即可自动开启公网访问。

安装

npm install @anima/next

使用

在您的 Next.js 项目中,通过配置文件集成 Anima:

// next.config.js
const { withAnima } = require('@anima/next');

const nextConfig = {
// 您的 Next.js 配置
};

module.exports = withAnima(nextConfig, {
token: process.env.ANIMA_TOKEN,
subdomain: 'my-nextjs-app',
autoStart: true,
onReady: (url) => {
console.log(`🚀 Anima 隧道已就绪: ${url}`);
}
});

开发环境自动启用

npm run dev
# 自动输出:
# ✓ Next.js 开发服务器启动: http://localhost:3000
# 🌐 公网地址: https://my-nextjs-app.anima4.cn

配置选项

参数类型默认值说明
tokenstringrequiredAnima API Token,用于认证和创建隧道
subdomainstringauto自定义子域名,例如 myapp 会生成 myapp.anima4.cn
domainstringnull自定义域名,需在 Anima 后台配置
autoStartbooleantrue是否在开发服务器启动时自动开启隧道
onReadyfunctionnull隧道就绪时的回调函数,参数为公网 URL

示例项目

查看完整的 Next.js 示例项目:GitHub 仓库链接