diff --git a/defi/src/api2/index.ts b/defi/src/api2/index.ts index ebbd5e8154..5a4e537030 100644 --- a/defi/src/api2/index.ts +++ b/defi/src/api2/index.ts @@ -20,6 +20,7 @@ async function main() { webserver.use((_req, res, next) => { res.append('Access-Control-Allow-Origin', '*'); res.append('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS'); + res.append('Access-Control-Allow-Headers', 'Authorization, Content-Type, X-Internal-Key'); next(); }); diff --git a/defi/src/api2/routes/index.ts b/defi/src/api2/routes/index.ts index bbded48d85..0edf70b2b5 100644 --- a/defi/src/api2/routes/index.ts +++ b/defi/src/api2/routes/index.ts @@ -23,6 +23,7 @@ import { getDimensionsMetadata } from "../utils/dimensionsUtils"; import { chainNameToIdMap } from "../../utils/normalizeChain"; import { getCategoryChartByChainData, getTagChartByChainData } from "../../getCategoryChartByChainData"; import { getCexs } from "../../getCexs"; +import { authWrapper } from "../utils/auth"; /* import { getProtocolUsersHandler } from "../../getProtocolUsers"; import { getActiveUsers } from "../../getActiveUsers"; @@ -79,8 +80,8 @@ export default function setRoutes(router: HyperExpress.Router, routerBasePath: s router.get("/charts/tags/:tag", ew(getTagChartByChainData)); router.get("/charts/tags/:tag/:chain", ew(getTagChartByChainData)); - router.get("/simpleChainDataset/:chain", ew(getSimpleChainDataset)); - router.get("/dataset/:protocol", ew(getDataset)); + router.get("/simpleChainDataset/:chain", authWrapper(getSimpleChainDataset)); + router.get("/dataset/:protocol", authWrapper(getDataset)); router.get("/cexs", ew(getCexs)); diff --git a/defi/src/api2/utils/auth.ts b/defi/src/api2/utils/auth.ts index cdfcccca10..8fb42bb6da 100644 --- a/defi/src/api2/utils/auth.ts +++ b/defi/src/api2/utils/auth.ts @@ -86,7 +86,11 @@ export async function validateSubscriptionAuth(authHeader: string): Promise<{ su export function authWrapper(routeHandler: (req: HyperExpress.Request, res: HyperExpress.Response) => Promise) { return ew(async (req: HyperExpress.Request, res: HyperExpress.Response) => { const authHeader = req.headers.authorization; - + const internalKey = req.headers['x-internal-key']; + if (internalKey && internalKey === process.env.INTERNAL_API_KEY) { + return routeHandler(req, res); + } + const authResult = await validateSubscriptionAuth(authHeader); if (!authResult.success) {