Integrating with a new API framework; vercel dev

I’ve created an API framework, and wanted to test it with Vercel. I figured using the cli tool and vercel dev would be the thing to do here, but it’s not working.

In the Vercel dashboard for my project, I am using “Other” as the framework, and defining an output directory and build command (using bun to execute the build command).

When I run vercel dev, it fires up and says things are available at http://localhost:3000, but when I use Postman to do a GET request to /, it returns the literal javascript output from my index.js built file.

My framework is very similar to Hono, in that the main index.ts file is doing a default export with a fetch method on it. The below is the built contents of that file. When I request the API endpoint, instead of the code being executed, it is literally returning the index.js content.

Any ideas on what I’m missing?

import { Xin } from "@xinkjs/xin";
const api = new Xin();
api.route("/").get((event) => event.text("Hello from Xin!"));
export default api;

Based on some AI asks, I’ve even set the config for the edge runtime, as well as put things in an api directory.

Still just get the source file content sent to me.

Ok, so I have things sort of working now, by putting index.ts inside of the /api directory. The issue is that this forces me to have a prefix for my entire API of /api; which shouldn’t be necessary.

I can hack around that by setting up the following vercel.json config, but it doesn’t feel like this should be required by users of my API framework; and, as far as I know, it’s not required by users of Hono. I understand Hono has some kind of built-in integration, but still.

{
  "$schema": "https://openapi.vercel.sh/vercel.json",
  "rewrites": [
    { "source": "/", "destination": "/api"}
  ]
}

It seems like Vercel should have a way of natively supporting any API framework that has a default export with a fetch method without the requirement of it being inside an /api directory.

What if there was a “Framework Preset” option of something like “Fetch Export” or “Default Export”? And as long as your entrypoint has an export default statement, then it should work with zero config.

Thought I’d have some fun, so I submitted a PR to add zero config support for the type of frameworks I mentioned here.

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