#how to debug api endpoint giving 404?

1 messages · Page 1 of 1 (latest)

serene hearth
#

i tried to convert my simple express proxy server to serverless vercel code. i made the static file serving work. for somereason i can not get any endpoint to work. everything gives 404. build logs and details shows i have the functions at the right place api/test but i cant access them on the browser (url.com/api/test or url.com/test). i tried fixing it for like 3 hours. completely started from scratch once. now i want some human ideas.

my project structure

api
-test.ts
public
-index.html
vercel.json

test.ts

import { VercelRequest, VercelResponse } from '@vercel/node';
export default function handler(req: VercelRequest, res: VercelResponse) {
    res.status(200).json({ message: 'Hello' });
}

vercel.json

{
    "build": {
        "env": {
            "NODE_ENV": "production"
        }
    },
    "installCommand": "corepack enable && corepack prepare pnpm@10.0.0 --activate && pnpm install",
    "builds": [
        {
            "src": "public/**",
            "use": "@vercel/static"
        },
        {
            "src": "api/**/*.ts",
            "use": "@vercel/node"
        }
    ],
    "routes": [
        {
            "src": "/",
            "dest": "/public/index.html"
        },
        {
            "src": "/api/(.*)",
            "dest": "/api/$1"
        }
    ]
}

im assuming tsconfig.json can't cause any issues right? i did some fiddling with it but idk

do i have to specify each endpoint in the routes with that format? i thought it would be automatic. (tbh both didnt work)

I've tried in both local and production environments (both in hosted version and local vercel-cli version)

zinc riverBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

serene hearth
#

I have only done serverless conversions with JS once before and was pretty straight forward

#

so like..

#

hm

#

is this a compiled file location problem

#

i was told to not worry about their existence when working with vercel dev

neon cairn
#

(the deployments will be taken down in a couple days)

#

entire project is just these two files

serene hearth
serene hearth
#

this is how my code looks like and i get 404 at the test page

#

let me try without any vercel json as you suggested

#

wow bruh

#

you are right. it just worked

#

what the issue here? the pnpm bs? imma check it

neon cairn
#

since here you are not relying on any custom behaviours – vercel understands api and public automatically – vercel.json is not required because you don't need to alter any default behaviour

#

when that happens, having it does more harm than good

serene hearth
#

im unable to use vercel local development because of pnpm tho

#
> Creating initial build
Detected `pnpm-lock.yaml` 9 which may be generated by pnpm@9.x or pnpm@10.x
Using pnpm@9.x based on project creation date
To use pnpm@10.x, manually opt in using corepack (https://vercel.com/docs/deployments/configure-a-build#corepack)
'yarn' is not recognized as an internal or external command,
operable program or batch file.
#

(i dont have yarn installed)

#

ok google says it sohuld support pnpm v10 but idk

neon cairn
#

just add the packageManager field to your package.json

serene hearth
#

it exist. i think i need to delete the .vercel folder so when i initialize, it works with pnpm10. website says something like that.

New projects with a pnpm-lock.yaml file with lockfileVersion: '9.0' will automatically use pnpm v10 for Install and Build Commands. Existing projects will continue to use pnpm v9 for backwards compatibility, since pnpm v9 also uses lockfileVersion: '9.0'

tho i dont think this project was initialized that much old

neon cairn
#

my guess is you have a yarn.lock file, remove it

#

if not there is no reason for vercel cli to think you are using yarn

serene hearth
#

i dont have yarn.lock file. ive never installed or used yarn before.

#

if it doesnt give that yarn error its fine

serene hearth
#

okay nvm i did some fiddling and

Vercel CLI 41.7.2
> Creating initial build
Detected `pnpm-lock.yaml` 9 which may be generated by pnpm@9.x or pnpm@10.x
Using pnpm@9.x based on project creation date
To use pnpm@10.x, manually opt in using corepack (https://vercel.com/docs/deployments/configure-a-build#corepack)
Running "pnpm run build"

> proxy@1.0.0 build C:\Users\Rt_Sa\DEV\proxy
> tsc

> Success! Build completed
> Ready! Available at http://localhost:3000

at least it doesnt whine about yarn now and works