vite-plugin-api-routes
Advanced tools
Comparing version 1.1.0-beta to 1.1.1-beta
{ | ||
"name": "vite-plugin-api-routes", | ||
"version": "1.1.0-beta", | ||
"version": "1.1.1-beta", | ||
"type": "module", | ||
@@ -38,2 +38,5 @@ "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.", | ||
}, | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"exports": { | ||
@@ -40,0 +43,0 @@ ".": { |
@@ -272,42 +272,38 @@ # vite-plugin-api-routes | ||
```typescript | ||
import { NextFunction, Request, Response, } from "express"; | ||
import express from "express"; | ||
import { CallbackHook, StatusHook, ServerHook, HandlerHook, ViteServerHook } from "vite-plugin-api-routes/model"; | ||
// WARNING: Please don't include the VITE TYPES here, because it has a problem when you build the project | ||
const devServerBefore = (viteServer: any, vite: any): void => { | ||
console.log("devServerBefore"); | ||
export const viteServerBefore: ViteServerHook = (server, viteServer) => { | ||
console.log("VITEJS SERVER"); | ||
server.use(express.json()); | ||
server.use(express.urlencoded({ extended: true })); | ||
}; | ||
const serverBefore = (server: Express) => { | ||
console.log("serverBefore"); | ||
export const viteServerAfter: ViteServerHook = (server, viteServer) => { | ||
}; | ||
const serverAfter = (server: Express) => { | ||
console.log("serverAfter"); | ||
} | ||
export const serverBefore: ServerHook = (server) => { | ||
server.use(express.json()); | ||
server.use(express.urlencoded({ extended: true })); | ||
}; | ||
const handlerBefore = (handler: Express) => { | ||
handler.use(express.json()); | ||
handler.use(express.urlencoded({ extended: true })); | ||
export const serverAfter: ServerHook = (server) => { | ||
}; | ||
const handlerAfter = (server: Express) => { | ||
console.log("handlerAfter"); | ||
} | ||
export const handlerBefore: HandlerHook = (handler) => { | ||
}; | ||
type RouteModule = (req: Request, res: Response, next: NextFunction) => void; | ||
export const handlerAfter: HandlerHook = (server) => { | ||
}; | ||
const callbackBefore = (callback: RouteModule, route: any) => { | ||
console.log("callbackBefore", callback); | ||
export const callbackBefore: CallbackHook = (callback, route) => { | ||
return callback; | ||
}; | ||
export default { | ||
devServerBefore, | ||
serverBefore, | ||
serverAfter, | ||
handlerBefore, | ||
handlerAfter, | ||
callbackBefore, | ||
} | ||
export const serverListening: StatusHook = (server) => { | ||
}; | ||
export const serverError: StatusHook = (server, error) => { | ||
}; | ||
``` | ||
@@ -349,5 +345,11 @@ | ||
## WARNING: | ||
Be cautious when configuring the `viteServerBefore` and `viteServerAfter` methods. These methods interact with viteServer, and if not configured correctly, they can lead to issues. Specifically, including a direct reference to the Vite.js library within these methods can cause problems during the build process. Although these methods themselves are not included in the final build output, any import references associated with the vitejs libraries can generate unexpected problems. | ||
## TO DO: | ||
- Duplicate declaration (**GET** in _/user.ts_ and _/user/index.ts_). Handler definition is required. | ||
- Extend the `mapper` attribute to support custom HTTP methods using a header attribute. | ||
- Implement fs-visitor for optimize the scan files process | ||
- express.on("error", callback) don't works | ||
- Set default error handling to `server After` or `handler After` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
38793
354
0