unjs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.unjs.io
MIT License
5.89k stars 496 forks source link

feat(open-api): production mode #2570

Closed pi0 closed 1 month ago

pi0 commented 3 months ago

This PR adds support to enable the open API route in the production build output.

Resolves #2418 (experimentally!)

New configs (openAPI: {})

[!NOTE] New routes removed /_nitro prefix to be simpler.

Security

Production rotues are explicit opt-in to make sure users deliberately want to expose available routes in the production and make necessary protection if needed.

production: 'runtime'

Ideally before moving the OpenAPI feature to stable, we will have guard route rules to allow a hookable method to protect routes.

In the meantime, in this mode a server middleware can be used to protect

production: 'prerender'

Prerender mode is most efficient because the JSON output is literally a constant response but the case is, the deployment presets that natively have a CDN (netlify, cloudflare, vercel, etc) never hit nitro server and in this mode, protection should be considered on CDN level somehow.