Go Modules proxy middleware designed for Next.js 13+, with perfect Vercel support.
- ✅ Out-of-the-box, simple configuration
- ✅ Support for personalized Go Modules addresses with aliases
- ✅ No Nginx dependency, perfect Vercel deployment support
- ✅ Compatible with Next.js 13.0+ (App Router & Pages Router)
- ✅ TypeScript support, configurable caching, debug mode
- ✅ Cross-version compatibility (avoids Next.js type conflicts)
# npm
npm install next-go-modules
# yarn
yarn add next-go-modules
# pnpm
pnpm add next-go-modules# Auto-generate all necessary files
npx next-go-modules init
# Or if installed globally
next-go-modules initThis will automatically create:
config/go-modules.ts- Module configuration filemiddleware.ts- Next.js middleware- API route files (automatically detects App Router or Pages Router)
Then simply edit config/go-modules.ts to add your Go modules configuration.
Note
If your project already has a middleware.ts file, the CLI tool will provide integration guidance instead of overwriting the existing file.
// config/go-modules.tsimport{GoModulesConfig}from'next-go-modules'exportconstgoModulesConfig: GoModulesConfig={modules: {'my-go-tool': {name: 'my-go-tool',fullName: 'yourdomain.com/my-go-tool',repo: 'https://github.com/yourusername/my-go-tool',description: 'Your Go tool description',install: 'go get -u yourdomain.com/my-go-tool',version: 'v1.0.0',aliases: ['tool'],// Optional aliases},// Add more modules here...},}Option A: Using the helper function (Recommended for Next.js 15)
// src/middleware.ts (if using src directory) or middleware.ts (project root)import{createGoModulesMiddleware}from'next-go-modules'import{goModulesConfig}from'./config/go-modules'constgoModulesMiddleware=createGoModulesMiddleware({config: goModulesConfig,debug: process.env.NODE_ENV==='development',})exportdefaultfunctionmiddleware(request: any){returngoModulesMiddleware(request)}exportconstconfig={matcher: ['/((?!api|_next/static|_next/image|favicon.ico|manifest.webmanifest|sitemap.xml).*)',],}// app/api/go-modules/[...module]/route.ts (App Router)import{createGoModulesApiRoute,createGoModulesHeadRoute}from'next-go-modules'import{goModulesConfig}from'../../../../config/go-modules'exportconstGET=createGoModulesApiRoute(goModulesConfig)exportconstHEAD=createGoModulesHeadRoute(goModulesConfig)Or using Pages Router:
// pages/api/go-modules/[...module].ts (Pages Router)import{createGoModulesApiRoute}from'next-go-modules'import{goModulesConfig}from'../../../config/go-modules'exportdefaultcreateGoModulesApiRoute(goModulesConfig)Now your Go modules will be accessible at:
/my-go-tool- Main path/tool- Alias path/my-go-tool?go-get=1- With go-get parameter
Users can install your Go modules with:
go get -u yourdomain.com/my-go-toolinterfaceGoModule{name: string// Module namefullName: string// Full module path (e.g., 'example.com/module')repo: string// Repository URLdescription: string// Module descriptioninstall: string// Installation commandtags?: string[]// Optional tagsversion?: string// Optional versionaliases?: string[]// Optional aliases}interfaceGoModulesConfig{modules: Record<string,GoModule>apiRoute?: string// Default: '/api/go-modules'matcher?: string[]// Default: excludes static filescacheControl?: string// Default: 'public, max-age=3600'}interfaceMiddlewareOptions{config: GoModulesConfigdebug?: boolean// Enable debug logging}constconfig: GoModulesConfig={modules: {/* your modules */},apiRoute: '/api/custom-go-modules',}constconfig: GoModulesConfig={modules: {/* your modules */},cacheControl: 'public, max-age=7200',// 2 hours}constconfig: GoModulesConfig={modules: {/* your modules */},matcher: ['/((?!api|_next|favicon.ico).*)',],}constmiddleware=createGoModulesMiddleware({config: goModulesConfig,debug: true,// Enable console logging})If you already have middleware, you can use the compose function:
// middleware.tsimport{composeMiddleware,createGoModulesMiddleware}from'next-go-modules'import{goModulesConfig}from'./config/go-modules'// Your existing middlewarefunctionyourExistingMiddleware(request){// Your logic}// Go modules middlewareconstgoModulesMiddleware=createGoModulesMiddleware({config: goModulesConfig,debug: process.env.NODE_ENV==='development',})// Compose middlewaresexportdefaultcomposeMiddleware(goModulesMiddleware,yourExistingMiddleware)getGoModule(modulePath, modules)- Get module by path or aliasgetAllGoModules(modules)- Get all modulesgetAllModulePaths(modules)- Get all available pathsgenerateGoModuleHTML(module)- Generate HTML for module
createGoModulesMiddleware(options)- Create middleware functiongetGoModulesMiddlewareConfig(options)- Get middleware config
createGoModulesApiRoute(config)- Create GET handlercreateGoModulesHeadRoute(config)- Create HEAD handler
constconfig: GoModulesConfig={modules: {'go-masker': {name: 'go-masker',fullName: 'normalcoder.com/go-masker',repo: 'https://github.com/normal-coder/go-masker',description: 'Data masking tool',install: 'go get -u normalcoder.com/go-masker',aliases: ['masker','data-masker'],},'go-validator': {name: 'go-validator',fullName: 'normalcoder.com/go-validator',repo: 'https://github.com/normal-coder/go-validator',description: 'Data validation tool',install: 'go get -u normalcoder.com/go-validator',aliases: ['validator','validate'],},},}This supports:
/go-masker,/masker,/data-masker/go-validator,/validator,/validate
This package works seamlessly with Vercel deployment. No additional configuration needed.
The middleware is compatible with any platform that supports Next.js middleware.
# Clone repository
git clone https://github.com/normal-coder/next-go-modules.git
cd next-go-modules
# Install dependencies
pnpm install
# Development mode
pnpm dev
# Lint code
pnpm lint
# Build
pnpm buildThis project uses Conventional Commits:
# Use commitizen for interactive commits
pnpm commit
# Or manually follow the format
git commit -m "feat: add new feature"
git commit -m "fix: resolve issue"
git commit -m "docs: update readme"Using Changesets for version management:
# Add changeset
pnpm changeset
# Version packages
pnpm version
# Release to npm
pnpm release- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
pnpm commit) - Push to the branch (
git push origin feature/amazing-feature) - Create a Pull Request
- Next.js - React full-stack framework
- TypeScript
- ESLint
- Husky
- Changesets
- Commitizen
MIT License - see LICENSE file for details.
