Skip to content

Commit

Permalink
Merge pull request #26 from yracnet/v1.1.x
Browse files Browse the repository at this point in the history
+ Fix configureServer after vite inicialize
  • Loading branch information
yracnet authored Nov 13, 2024
2 parents 632f2fa + 7d74b89 commit 4021b29
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 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.10",
"version": "1.1.11",
"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.4.4",
"vite": "^2.0.0"
}
}
}
31 changes: 17 additions & 14 deletions src/plugin/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,23 @@ export const pluginImpl = (config: PluginConfig): PluginOption => {
});
//@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,
});
module.handler(req, res, next);
} catch (error) {
ssrFixStacktrace(error as Error);
process.exitCode = 1;
next(error);
}
});
//@ts-ignore
configure.viteServerAfter?.(devServer.middlewares, devServer, vite);
return () => {
// Register Proxy After Vite Inicialize
middlewares.use(baseApi, async (req, res, next) => {
try {
const { handler } = await ssrLoadModule(config.handler, {
fixStacktrace: true,
});
handler(req, res, next);
} catch (error) {
ssrFixStacktrace(error as Error);
process.exitCode = 1;
next(error);
}
});
//@ts-ignore
configure.viteServerAfter?.(devServer.middlewares, devServer, vite);
};
},
writeBundle: async () => {
if (process.env.IS_API_BUILD) return;
Expand Down

0 comments on commit 4021b29

Please sign in to comment.