![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
vite-plugin-api
Advanced tools
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.
Enhance API routing in ViteJS based on directory structure for improved visibility and project structure in Node.js and Express.
See the tutorial
> tree src/api/
src/api/:
├───v1
│ │ auth.js
│ │ index.js
│ ├───auth
│ │ login.js
│ │ status.js
│ └───user
│ $userId.js //Remix Format
│ index.js
└───v2
│ user.js
├───auth
│ login.js
│ status.js
└───user
index.js
[userId].js //NextJS Format
The directory tree is exported as router rules tree:
GET /api/v1
USE /api/v1/auth
PUT /api/v1/auth
DELETE /api/v1/auth
GET /api/v1/auth/login
POST /api/v1/auth/login
GET /api/v1/auth/status
POST /api/v1/auth/status
GET /api/v1/user/
POST /api/v1/user/
PUT /api/v1/user/:userId
DELETE /api/v1/user/:userId
GET /api/v2/auth/login
POST /api/v2/auth/login
GET /api/v2/auth/status
POST /api/v2/auth/status
USE /api/v2/user
PUT /api/v2/user
DELETE /api/v2/user
GET /api/v2/user/
POST /api/v2/user/
PUT /api/v2/user/:userId
DELETE /api/v2/user/:userId
For example, the src/api/v1/user/$userId.js
file exports allowed request methods:
//file:src/api/v1/user/$userId.js
export const DELETE = (req, res, next) => {
res.send("DELETE REQUEST");
};
export const PUT = async (req, res, next) => {
res.send("PUT REQUEST");
};
// Support default, GET, HEAD, POST, PUT, DELETE by default
// For CONNECT, OPTIONS, TRACE, PATCH, and others, you need to add the mapping to the mapper attribute config
Similarly, the [userId].js
or $userId.js
file name is exported as a request parameter /user/:userId
, following the Next.js/Remix framework.
yarn add vite-plugin-api
In vite.config.ts
:
import { defineConfig } from "vite";
import { pluginAPI } from "vite-plugin-api";
export default defineConfig({
plugins: [
pluginAPI({
// routeBase?: "api",
// dirs?: [{ dir: "src/api"; route: "", exclude?: ["*.txt", ".csv", "data/*.*"] }],
// include?: ["**/*.js", "**/*.ts"],
// exclude?: ["node_modules", ".git"],
// moduleId?: "virtual:vite-plugin-api",
// mapper?: { default: "use", GET: "get", ... },
// entry?: "[node_module:lib]/server.js",
// handler?: "[node_module:lib]/handler.js",
}),
],
});
Default Value
mapper: {
default: "use",
GET: "get",
POST: "post",
PUT: "put",
PATCH: "patch",
DELETE: "delete",
// Overwrite
...mapper,
};
/vite.config.js
export default defineConfig({
plugins: [
createAPI({
entry: "src/custom-server.js",
mapper: {
PING: "get",
// export const PING = ()=>{...}
// Will be mapped to express method
// app.get('/path/dir', PING)
OTHER_POST: "post2",
// export const PATCH = ()=>{...}
// Will not be mapped
PATCH: false,
},
}),
],
});
You can disable a method by setting its value to false. In the example PATCH: false
, the PATCH method is disabled.
/src/api/index.js
export PING = (req, res, next)=>{
res.send({name:"Ping Service"});
}
export OTHER_POST = (req, res, next)=>{
res.send({name:"Ping Service"});
}
export PATCH = (req, res, next)=>{
res.send({name:"Ping Service"});
}
/src/custom-server.js or see entry-server.js
import express from "express";
import { applyRouters } from "virtual:vite-plugin-api:router";
const app = express();
app.post2 = (req, res, next) => {
console.log("Custom POST2");
app.post(req, res, next);
};
applyRouters(
(props) => {
const { source, method, path, route, cb } = props;
// route is a path without routeBase
// source is a full path file
if (app[method]) {
app[method](path, cb);
} else {
console.log("App does not support", method, "verbose");
}
},
(cb) => async (req, res, next) => {
try {
res.message = "My high order component for callback";
await cb(req, res, next);
} catch (error) {
next(error);
}
}
);
app.listen(3000, () => {
console.log("Ready at http://localhost:3000");
});
To load the definition package for "virtual:vite-plugin-api:config" and "virtual:vite-plugin-api:router", add: src/env.d.ts
/// <reference types="vite-plugin-api/client" />
Only keys starting with the prefix "API_" will be loaded into process.env
.
mapper
attribute to support custom HTTP methods using a header attribute.FAQs
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.
The npm package vite-plugin-api receives a total of 0 weekly downloads. As such, vite-plugin-api popularity was classified as not popular.
We found that vite-plugin-api demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.