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;
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.
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.