vite-plugin-api-routes
Version:
A Vite.js plugin that creates API routes by mapping the directory structure, similar to Next.js API Routes. This plugin enhances the functionality for backend development using Vite.
23 lines (22 loc) • 607 B
JavaScript
// src/api-server/handler.ts
import express from "express";
import * as configure from "vite-plugin-api-routes/configure";
import { applyRouters } from "vite-plugin-api-routes/routers";
var handler = express();
configure.handlerBefore?.(handler);
applyRouters((props) => {
const { method, route, path, cb } = props;
if (handler[method]) {
if (Array.isArray(cb)) {
handler[method](route, ...cb);
} else {
handler[method](route, cb);
}
} else {
console.log("Not Support", method, "for", route, "in", handler);
}
});
configure.handlerAfter?.(handler);
export {
handler
};