Skip to content

Commit

Permalink
Merge pull request #21 from yracnet/v1.1.x-beta
Browse files Browse the repository at this point in the history
+ FIX  #20
  • Loading branch information
yracnet authored Mar 15, 2024
2 parents 499e06e + 7c9a9c9 commit f68084b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vite-plugin-api-routes",
"version": "1.1.2-beta",
"version": "1.1.3-beta",
"type": "module",
"description": "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.",
"keywords": [
Expand Down Expand Up @@ -72,4 +72,4 @@
"typescript": "^5.3.3",
"vite": "^2.0.0"
}
}
}
10 changes: 7 additions & 3 deletions src/plugin/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,16 @@ export const pluginImpl = (config: PluginConfig): PluginOption => {
watcher.on("add", onReload);
watcher.on("change", onReload);
const baseApi = path.join(vite.base, config.routeBase);
const configure = await ssrLoadModule(config.configure, { fixStacktrace: true });
const configure = await ssrLoadModule(config.configure, {
fixStacktrace: true,
});
//@ts-ignore
configure.viteServerBefore?.(devServer.middlewares, devServer, vite);
middlewares.use(baseApi, async (req: any, res, next) => {
try {
const module = await ssrLoadModule(config.handler, { fixStacktrace: true });
const module = await ssrLoadModule(config.handler, {
fixStacktrace: true,
});
module.handler(req, res, next);
} catch (error) {
ssrFixStacktrace(error as Error);
Expand Down Expand Up @@ -103,7 +107,7 @@ export const pluginImpl = (config: PluginConfig): PluginOption => {
onwarn: (warning: any, handler: any) => {
if (
warning.code === "MISSING_EXPORT" &&
warning.id === config.routersFile
warning.id.startsWith(config.cacheDir)
) {
return;
}
Expand Down
7 changes: 4 additions & 3 deletions src/plugin/write/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ export type FileRouter = {
};

const sortURLParams = (a: string, b: string) => {
a = a.replace(/\:|\$|\[/gi, 'zz');
b = b.replace(/\:|\$|\[/gi, 'zz');
a = a.replace(/\:|\$|\[/gi, "zz");
b = b.replace(/\:|\$|\[/gi, "zz");
return a.localeCompare(b);
}
};

export const getFileRouters = (config: PluginConfig): FileRouter[] => {
let { dirs, include, exclude } = config;
Expand All @@ -55,6 +55,7 @@ export const getFileRouters = (config: PluginConfig): FileRouter[] => {
route = path.join("/", route);
const pathName = path.join("/", config.routeBase, route);
file = path.join(it.dir, file);
file = path.relative(config.root, file);
return {
order: jx,
name: `_${ix}_${jx}`,
Expand Down

0 comments on commit f68084b

Please sign in to comment.