Gin gives "pattern matches no files" error

How can I deploy my project to serverless functions without “unable to match html templates” error?

I have my code setup so it finds external html file templates in the “external/html” directory using the LoadHtmlGlob function gin provides.

Instead of loading and serving the html content, it instead errors saying that the pattern provided can’t find any files.

// api/index.go
func Handler(w http.ResponseWriter, req *http.Request) {
  gin.SetMode(gin.ReleaseMode)
  r := gin.Default()
 
  r.Use(Cors())
  r.LoadHtmlGlob("/external/html/*.html")
  //***
}
//vercel.json
{
    "version": 2,
    "routes": [
      {
        "src": "/(.*)",
        "dest": "/api/index.go"
      }
    ]
  }

Project structure:
.
├── api
│ └── index.go
├── external
│ ├── html
│ ├── models
│ └── util
│ ├── bucket.go
│ ├── database.go
│ └── redis.go
├── .env.local
├── .env.prod
├── .gitignore
├── go.mod
└── go.sum

Hi @butterfriez, welcome to the Vercel Community!

Have you tried using the includeFiles option from the Function | Project Configuration in your vercel.json?

I think including the file in your function code should resolve the issue.

I’d also recommend removing the legacy routes option and use the rewrites option instead.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.