mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-09 00:18:00 +01:00
refactor: always accept any content type for GET reqs (#1672)
This commit is contained in:
parent
e5fe268844
commit
9aa1f39add
@ -31,7 +31,6 @@ export default class ArchiveController extends Controller {
|
|||||||
this.route({
|
this.route({
|
||||||
method: 'get',
|
method: 'get',
|
||||||
path: '/features',
|
path: '/features',
|
||||||
acceptAnyContentType: true,
|
|
||||||
handler: this.getArchivedFeatures,
|
handler: this.getArchivedFeatures,
|
||||||
permission: NONE,
|
permission: NONE,
|
||||||
middleware: [
|
middleware: [
|
||||||
@ -46,7 +45,6 @@ export default class ArchiveController extends Controller {
|
|||||||
this.route({
|
this.route({
|
||||||
method: 'get',
|
method: 'get',
|
||||||
path: '/features/:projectId',
|
path: '/features/:projectId',
|
||||||
acceptAnyContentType: true,
|
|
||||||
handler: this.getArchivedFeaturesByProjectId,
|
handler: this.getArchivedFeaturesByProjectId,
|
||||||
permission: NONE,
|
permission: NONE,
|
||||||
middleware: [
|
middleware: [
|
||||||
|
@ -69,7 +69,6 @@ class FeatureController extends Controller {
|
|||||||
this.route({
|
this.route({
|
||||||
method: 'get',
|
method: 'get',
|
||||||
path: '',
|
path: '',
|
||||||
acceptAnyContentType: true,
|
|
||||||
handler: this.getAllToggles,
|
handler: this.getAllToggles,
|
||||||
permission: NONE,
|
permission: NONE,
|
||||||
middleware: [
|
middleware: [
|
||||||
@ -100,7 +99,6 @@ class FeatureController extends Controller {
|
|||||||
method: 'get',
|
method: 'get',
|
||||||
path: '/:featureName/tags',
|
path: '/:featureName/tags',
|
||||||
handler: this.listTags,
|
handler: this.listTags,
|
||||||
acceptAnyContentType: true,
|
|
||||||
permission: NONE,
|
permission: NONE,
|
||||||
middleware: [
|
middleware: [
|
||||||
openApiService.validPath({
|
openApiService.validPath({
|
||||||
|
@ -86,7 +86,6 @@ export default class ProjectFeaturesController extends Controller {
|
|||||||
this.route({
|
this.route({
|
||||||
method: 'get',
|
method: 'get',
|
||||||
path: PATH_ENV,
|
path: PATH_ENV,
|
||||||
acceptAnyContentType: true,
|
|
||||||
permission: NONE,
|
permission: NONE,
|
||||||
handler: this.getEnvironment,
|
handler: this.getEnvironment,
|
||||||
middleware: [
|
middleware: [
|
||||||
@ -130,7 +129,6 @@ export default class ProjectFeaturesController extends Controller {
|
|||||||
method: 'get',
|
method: 'get',
|
||||||
path: PATH_STRATEGIES,
|
path: PATH_STRATEGIES,
|
||||||
handler: this.getStrategies,
|
handler: this.getStrategies,
|
||||||
acceptAnyContentType: true,
|
|
||||||
permission: NONE,
|
permission: NONE,
|
||||||
middleware: [
|
middleware: [
|
||||||
openApiService.validPath({
|
openApiService.validPath({
|
||||||
@ -160,7 +158,6 @@ export default class ProjectFeaturesController extends Controller {
|
|||||||
method: 'get',
|
method: 'get',
|
||||||
path: PATH_STRATEGY,
|
path: PATH_STRATEGY,
|
||||||
handler: this.getStrategy,
|
handler: this.getStrategy,
|
||||||
acceptAnyContentType: true,
|
|
||||||
permission: NONE,
|
permission: NONE,
|
||||||
middleware: [
|
middleware: [
|
||||||
openApiService.validPath({
|
openApiService.validPath({
|
||||||
@ -217,7 +214,6 @@ export default class ProjectFeaturesController extends Controller {
|
|||||||
this.route({
|
this.route({
|
||||||
method: 'get',
|
method: 'get',
|
||||||
path: PATH,
|
path: PATH,
|
||||||
acceptAnyContentType: true,
|
|
||||||
handler: this.getFeatures,
|
handler: this.getFeatures,
|
||||||
permission: NONE,
|
permission: NONE,
|
||||||
middleware: [
|
middleware: [
|
||||||
@ -263,7 +259,6 @@ export default class ProjectFeaturesController extends Controller {
|
|||||||
this.route({
|
this.route({
|
||||||
method: 'get',
|
method: 'get',
|
||||||
path: PATH_FEATURE,
|
path: PATH_FEATURE,
|
||||||
acceptAnyContentType: true,
|
|
||||||
handler: this.getFeature,
|
handler: this.getFeature,
|
||||||
permission: NONE,
|
permission: NONE,
|
||||||
middleware: [
|
middleware: [
|
||||||
|
@ -42,7 +42,6 @@ export default class VariantsController extends Controller {
|
|||||||
method: 'get',
|
method: 'get',
|
||||||
path: PREFIX,
|
path: PREFIX,
|
||||||
permission: NONE,
|
permission: NONE,
|
||||||
acceptAnyContentType: true,
|
|
||||||
handler: this.getVariants,
|
handler: this.getVariants,
|
||||||
middleware: [
|
middleware: [
|
||||||
openApiService.validPath({
|
openApiService.validPath({
|
||||||
|
@ -18,16 +18,25 @@ interface IRequestHandler<
|
|||||||
): Promise<void> | void;
|
): Promise<void> | void;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IRouteOptions {
|
interface IRouteOptionsBase {
|
||||||
method: 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
||||||
path: string;
|
path: string;
|
||||||
permission: string;
|
permission: string;
|
||||||
middleware?: RequestHandler[];
|
middleware?: RequestHandler[];
|
||||||
handler: IRequestHandler;
|
handler: IRequestHandler;
|
||||||
acceptAnyContentType?: boolean;
|
|
||||||
acceptedContentTypes?: string[];
|
acceptedContentTypes?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface IRouteOptionsGet extends IRouteOptionsBase {
|
||||||
|
method: 'get';
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IRouteOptionsNonGet extends IRouteOptionsBase {
|
||||||
|
method: 'post' | 'put' | 'patch' | 'delete';
|
||||||
|
acceptAnyContentType?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
type IRouteOptions = IRouteOptionsNonGet | IRouteOptionsGet;
|
||||||
|
|
||||||
const checkPermission = (permission) => async (req, res, next) => {
|
const checkPermission = (permission) => async (req, res, next) => {
|
||||||
if (!permission || permission === NONE) {
|
if (!permission || permission === NONE) {
|
||||||
return next();
|
return next();
|
||||||
@ -74,7 +83,7 @@ export default class Controller {
|
|||||||
private useContentTypeMiddleware(options: IRouteOptions): RequestHandler[] {
|
private useContentTypeMiddleware(options: IRouteOptions): RequestHandler[] {
|
||||||
const { middleware = [], acceptedContentTypes = [] } = options;
|
const { middleware = [], acceptedContentTypes = [] } = options;
|
||||||
|
|
||||||
return options.acceptAnyContentType
|
return options.method === 'get' || options.acceptAnyContentType
|
||||||
? middleware
|
? middleware
|
||||||
: [requireContentType(...acceptedContentTypes), ...middleware];
|
: [requireContentType(...acceptedContentTypes), ...middleware];
|
||||||
}
|
}
|
||||||
@ -94,7 +103,6 @@ export default class Controller {
|
|||||||
path,
|
path,
|
||||||
handler,
|
handler,
|
||||||
permission,
|
permission,
|
||||||
acceptAnyContentType: true,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user