Skip to content

Commit

Permalink
Revert "feat: Add granular CORS (#741)"
Browse files Browse the repository at this point in the history
This reverts commit f70ab2d.
  • Loading branch information
juanmahidalgo committed Apr 23, 2024
1 parent f70ab2d commit 55fbe1b
Show file tree
Hide file tree
Showing 27 changed files with 63 additions and 387 deletions.
14 changes: 1 addition & 13 deletions src/Analytics/Analytics.router.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,23 @@
import cacheControl from 'express-cache-controller'
import { server } from 'decentraland-server'
import { Router } from '../common/Router'
import { withCors } from '../middleware/cors'
import { Analytics } from './Analytics.model'
import { Request } from 'express'

export class AnalyticsRouter extends Router {
mount() {
/**
* CORS for the OPTIONS header
*/
this.router.options('/analytics/weekly', withCors)
this.router.options('/analytics/status', withCors)

/**
* Get weekly stats
*/
this.router.get(
'/analytics/weekly',
withCors,
cacheControl({ maxAge: 43200, public: true }),
server.handleRequest(this.getWeekly)
),
/**
* Get status
*/
this.router.get(
'/analytics/status',
withCors,
server.handleRequest(this.getStatus)
)
this.router.get('/analytics/status', server.handleRequest(this.getStatus))
}

async getWeekly(req: Request) {
Expand Down
12 changes: 1 addition & 11 deletions src/App/App.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,10 @@ import { server } from 'decentraland-server'
import { env } from 'decentraland-commons'

import { Router } from '../common/Router'
import { withPermissiveCors } from '../middleware/cors'

export class AppRouter extends Router {
mount() {
/**
* CORS for the OPTIONS header
*/
this.router.options('/info', withPermissiveCors)

this.router.get(
'/info',
withPermissiveCors,
server.handleRequest(this.getVersion)
)
this.router.get('/info', server.handleRequest(this.getVersion))
}

getVersion() {
Expand Down
12 changes: 1 addition & 11 deletions src/Asset/Asset.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Request } from 'express'
import { server } from 'decentraland-server'
import { hashV1 } from '@dcl/hashing'
import { Router } from '../common/Router'
import { withCors } from '../middleware/cors'
import {
withModelExists,
asMiddleware,
Expand All @@ -22,19 +21,11 @@ export class AssetRouter extends Router {
'assetPackId'
)

/**
* CORS for the OPTIONS header
*/
this.router.options('/assetPacks/:assetPackId/assets/:id/files', withCors)
this.router.options('/assets/:id', withCors)
this.router.options('/assets', withCors)

/**
* Upload the files for each asset in an asset pack
*/
this.router.post(
'/assetPacks/:assetPackId/assets/:id/files',
withCors,
withAuthentication,
withAssetPackExists,
withAssetPackAuthorization,
Expand All @@ -53,15 +44,14 @@ export class AssetRouter extends Router {
*/
this.router.get(
'/assets/:id',
withCors,
withAssetExists,
server.handleRequest(this.getAsset)
)

/**
* Get a multiple assets
*/
this.router.get('/assets', withCors, server.handleRequest(this.getAssets))
this.router.get('/assets', server.handleRequest(this.getAssets))
}

async assetBelongsToPackMiddleware(req: Request) {
Expand Down
13 changes: 0 additions & 13 deletions src/AssetPack/AssetPack.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { v4 as uuidv4 } from 'uuid'
import express from 'express'
import { ILoggerComponent } from '@well-known-components/interfaces'

import { withCors } from '../middleware/cors'
import { Router } from '../common/Router'
import { HTTPError, STATUS_CODES } from '../common/HTTPError'
import { getValidator } from '../utils/validator'
Expand Down Expand Up @@ -59,19 +58,11 @@ export class AssetPackRouter extends Router {
const withAssetPackExists = withModelExists(AssetPack)
const withAssetPackAuthorization = withModelAuthorization(AssetPack)

/**
* CORS for the OPTIONS header
*/
this.router.options('/assetPacks', withCors)
this.router.options('/assetPacks/:id', withCors)
this.router.options('/assetPacks/:id/thumbnail', withCors)

/**
* Get all asset packs
*/
this.router.get(
'/assetPacks',
withCors,
withPermissiveAuthentication,
withLowercaseQueryParams(['owner']),
asyncHandler(this.getAssetPacks)
Expand All @@ -82,7 +73,6 @@ export class AssetPackRouter extends Router {
*/
this.router.get(
'/assetPacks/:id',
withCors,
withPermissiveAuthentication,
server.handleRequest(this.getAssetPack)
)
Expand All @@ -92,7 +82,6 @@ export class AssetPackRouter extends Router {
*/
this.router.put(
'/assetPacks/:id',
withCors,
withAuthentication,
server.handleRequest(this.upsertAssetPack)
)
Expand All @@ -102,7 +91,6 @@ export class AssetPackRouter extends Router {
*/
this.router.delete(
'/assetPacks/:id',
withCors,
withAuthentication,
withAssetPackExists,
withAssetPackAuthorization,
Expand All @@ -114,7 +102,6 @@ export class AssetPackRouter extends Router {
*/
this.router.post(
'/assetPacks/:id/thumbnail',
withCors,
withAuthentication,
withAssetPackExists,
withAssetPackAuthorization,
Expand Down
23 changes: 0 additions & 23 deletions src/Collection/Collection.router.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Request, Response } from 'express'
import { server } from 'decentraland-server'
import { omit } from 'decentraland-commons/dist/utils'
import { withCors } from '../middleware/cors'
import { Router } from '../common/Router'
import { HTTPError, STATUS_CODES } from '../common/HTTPError'
import { getValidator } from '../utils/validator'
Expand Down Expand Up @@ -87,24 +86,11 @@ export class CollectionRouter extends Router {
)
const withLowercasedAddress = withLowercasedParams(['address'])

/**
* CORS for the OPTIONS header
*/
this.router.options('/collections', withCors)
this.router.options('/:address/collections', withCors)
this.router.options('/collections/:id', withCors)
this.router.options('/collections/:id/publish', withCors)
this.router.options('/collections/:id/tos', withCors)
this.router.options('/collections/:id/lock', withCors)
this.router.options('/collections/:id/approvalData', withCors)
this.router.options('/addresses', withCors)

/**
* Returns all collections
*/
this.router.get(
'/collections',
withCors,
withPermissiveAuthentication,
server.handleRequest(this.getCollections)
)
Expand All @@ -114,7 +100,6 @@ export class CollectionRouter extends Router {
*/
this.router.get(
'/:address/collections',
withCors,
withAuthentication,
withLowercasedAddress,
server.handleRequest(this.getAddressCollections)
Expand All @@ -125,7 +110,6 @@ export class CollectionRouter extends Router {
*/
this.router.get(
'/collections/:id',
withCors,
withAuthentication,
withCollectionExists,
server.handleRequest(this.getCollection)
Expand All @@ -136,7 +120,6 @@ export class CollectionRouter extends Router {
*/
this.router.post(
'/collections/:id/publish',
withCors,
withAuthentication,
withCollectionExists,
server.handleRequest(this.publishCollection)
Expand All @@ -147,7 +130,6 @@ export class CollectionRouter extends Router {
*/
this.router.post(
'/collections/:id/tos',
withCors,
withAuthentication,
withCollectionExists,
server.handleRequest(this.saveTOS)
Expand All @@ -158,7 +140,6 @@ export class CollectionRouter extends Router {
*/
this.router.post(
'/collections/:id/lock',
withCors,
withAuthentication,
withCollectionExists,
withCollectionAuthorization,
Expand All @@ -170,7 +151,6 @@ export class CollectionRouter extends Router {
*/
this.router.get(
'/collections/:id/approvalData',
withCors,
withAuthentication,
withCollectionExists,
server.handleRequest(this.getApprovalData)
Expand All @@ -182,7 +162,6 @@ export class CollectionRouter extends Router {
*/
this.router.put(
'/collections/:id',
withCors,
withAuthentication,
withSchemaValidation(upsertCollectionSchema),
server.handleRequest(this.upsertCollection)
Expand All @@ -193,7 +172,6 @@ export class CollectionRouter extends Router {
*/
this.router.delete(
'/collections/:id',
withCors,
withAuthentication,
withCollectionExists,
withCollectionAuthorization,
Expand All @@ -205,7 +183,6 @@ export class CollectionRouter extends Router {
*/
this.router.get(
'/addresses',
withCors,
server.handleRequest(this.getAddressesCollections)
)
}
Expand Down
12 changes: 1 addition & 11 deletions src/Committee/Committee.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,14 @@ import { utils } from 'decentraland-commons'
import { server } from 'decentraland-server'

import { Router } from '../common/Router'
import { withCors } from '../middleware/cors'
import { collectionAPI } from '../ethereum/api/collection'

export class CommitteeRouter extends Router {
mount() {
/**
* CORS for the OPTIONS header
*/
this.router.options('/committee', withCors)

/**
* Returns the addresses for the current committee
*/
this.router.get(
'/committee',
withCors,
server.handleRequest(this.getCommittee)
)
this.router.get('/committee', server.handleRequest(this.getCommittee))
}

async getCommittee() {
Expand Down
22 changes: 0 additions & 22 deletions src/Curation/Curation.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Router } from '../common/Router'
import { HTTPError, STATUS_CODES } from '../common/HTTPError'
import { withAuthentication, AuthRequest } from '../middleware'
import { isCommitteeMember } from '../Committee'
import { withCors } from '../middleware/cors'
import { collectionAPI } from '../ethereum/api/collection'
import { thirdPartyAPI } from '../ethereum/api/thirdParty'
import { getValidator } from '../utils/validator'
Expand Down Expand Up @@ -41,83 +40,62 @@ export class CurationRouter extends Router {
// - /collections/:id/curation -> /collectionCurations/:id
// - /items/:id/curation -> /itemCurations/:id
// - etc

/**
* CORS for the OPTIONS header
*/
this.router.options('/curations', withCors)
this.router.options('/collectionCuration/:id/itemsStats', withCors)
this.router.options('/collections/:id/itemCurations', withCors)
this.router.options('/collections/:id/curation', withCors)
this.router.options('/collections/:id/curation/post', withCors)
this.router.options('/items/:id/curation', withCors)

this.router.get(
'/curations',
withCors,
withAuthentication,
server.handleRequest(this.getCollectionCurations)
)

this.router.get(
'/collectionCuration/:id/itemsStats',
withCors,
withAuthentication,
server.handleRequest(this.getCollectionCurationItemStats)
)

this.router.get(
'/collections/:id/itemCurations',
withCors,
withAuthentication,
server.handleRequest(this.getCollectionItemCurations)
)

this.router.get(
'/collections/:id/curation',
withCors,
withAuthentication,
server.handleRequest(this.getCollectionCuration)
)

this.router.patch(
'/collections/:id/curation',
withCors,
withAuthentication,
server.handleRequest(this.updateCollectionCuration)
)

this.router.post(
'/collections/:id/curation',
withCors,
withAuthentication,
server.handleRequest(this.insertCollectionCuration)
)

this.router.post(
'/collections/:id/curation/post',
withCors,
withAuthentication,
server.handleRequest(this.createCurationNewAssigneePost)
)

this.router.get(
'/items/:id/curation',
withCors,
withAuthentication,
server.handleRequest(this.getItemCuration)
)

this.router.patch(
'/items/:id/curation',
withCors,
withAuthentication,
server.handleRequest(this.updateItemCuration)
)

this.router.post(
'/items/:id/curation',
withCors,
withAuthentication,
server.handleRequest(this.insertItemCuration)
)
Expand Down
Loading

0 comments on commit 55fbe1b

Please sign in to comment.