Vercel wildcard route's src results in 404 error in Hapi.js backend

17 Views Asked by At

I'm currently trying to deploy a TypeScript Hapi.js server to Vercel and facing difficulties with the deployment. I've tried following some express with TypeScript deployment tutorials, since I couldn't find any with Hapi.js. I ended writing this in my vercel.json:

{
    "version": 2,
    "builds": [
        {
            "src": "dist/src/index.js",
            "use": "@vercel/node",
            "config": { "includeFiles": ["dist/src/**"] }
        }
    ],
    "routes": [
        {
            "src": "/(.*)",
            "dest": "dist/src/index.js"
        }
    ]
}

And this doesn't work. I've tried to change the src to just / but it only worked for the base route and not other routes.

Here is the Github repo, if anyone wants to look at it. Thanks for any help in advance!

1

There are 1 best solutions below

0
VallenDra On

I ended up adding methods field to the vercel.json routes array and the deployment worked!

I found this configuration on this blog and by the looks of it, it should work on other typescript based backend server that you want to deploy on vercel.

{
    "version": 2,
    "builds": [
        {
            "src": "dist/src/index.js",
            "use": "@vercel/node"
        }
    ],
    "routes": [
        {
            "src": "/(.*)",
            "dest": "dist/src/index.js",
            "methods": ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"]
        }
    ]
}