yracnet / vite-plugin-api-routes

Create API routes from path directory like to Nextjs
MIT License
29 stars 4 forks source link

Does not parse JSON by default #7

Closed PlayWolfYT closed 1 year ago

PlayWolfYT commented 1 year ago

I think it would make sense to automatically parse JSON with the express json parser, otherwise people might get confused why their Request-Bodies are empty.

Looking at the code, I think the idea was that it is supposed to do that, though I found out that it does not.

Making the following changes to the src/plugin/write/handlerFile.ts would fix this:

//...
export const handler = express();

// Add JSON-Parsing
handler.use(express.json());
handler.use(express.urlencoded({ extended: true }));

//...
yracnet commented 1 year ago

It was applied in 1.0.2.