4655 batch endpoints on the rest api (#5411)
- add POST rest/batch/<OBJECT> endpoint - rearrange rest api code with Twenty quality standard - unify REST API error format - Added PATCH verb to update objects - In openapi schema, we replaced PUT with PATCH verb to comply with REST standard - fix openApi schema to match the REST api ### Batch Create  ### Replace PUT by PATCH in open Api  ### Error format unification   
This commit is contained in:
26
packages/twenty-server/src/utils/apply-cors-to-exceptions.ts
Normal file
26
packages/twenty-server/src/utils/apply-cors-to-exceptions.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { ExceptionFilter, Catch, ArgumentsHost } from '@nestjs/common';
|
||||
|
||||
import { Response } from 'express';
|
||||
|
||||
// In case of exception in middleware run before the CORS middleware (eg: JSON Middleware that checks the request body),
|
||||
// the CORS headers are missing in the response.
|
||||
// This class add CORS headers to exception response to avoid misleading CORS error
|
||||
@Catch()
|
||||
export class ApplyCorsToExceptions implements ExceptionFilter {
|
||||
catch(exception: any, host: ArgumentsHost) {
|
||||
const ctx = host.switchToHttp();
|
||||
const response = ctx.getResponse<Response>();
|
||||
|
||||
response.header('Access-Control-Allow-Origin', '*');
|
||||
response.header(
|
||||
'Access-Control-Allow-Methods',
|
||||
'GET,HEAD,PUT,PATCH,POST,DELETE',
|
||||
);
|
||||
response.header(
|
||||
'Access-Control-Allow-Headers',
|
||||
'Origin, X-Requested-With, Content-Type, Accept',
|
||||
);
|
||||
|
||||
response.status(exception.getStatus()).json(exception.response);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user