🚨 Breaking Changes 🚨
- Handlers have been rewritten to use native APIs in both
fetchand Node.js' HTTP server. - The options
onStart,onSuccess,onError, andonFinishhave been removed—use the new interceptors (onStart,onError, etc.) instead. OpenAPIServerHandlerandOpenAPIServerlessHandlerhas been removed nowOpenAPIHandleroptimized for both.
🌟 Plugins 🌟
We're introducing two plugins: CORSPlugin and ResponseHeadersPlugin.
const openAPIHandler = new OpenAPIHandler(router, {
schemaCoercers: [new ZodCoercer()],
interceptors: [
onError((error) => {
console.error(error);
}),
],
plugins: [
new CORSPlugin({ origin: 'http://localhost:3000' }),
new ResponseHeadersPlugin(),
],
});
export interface ORPCContext extends ResponseHeadersPluginContext {
// ResponseHeadersPluginContext is injected
user?: z.infer<typeof UserSchema>;
db?: any;
}
const pub = os
.$context<ORPCContext>()
.use(({ context, next }) => {
context.resHeaders?.set('x-custom-header', 'custom-value');
return next();
});