Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions defi/src/api2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down
5 changes: 3 additions & 2 deletions defi/src/api2/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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));

Expand Down
6 changes: 5 additions & 1 deletion defi/src/api2/utils/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ export async function validateSubscriptionAuth(authHeader: string): Promise<{ su
export function authWrapper(routeHandler: (req: HyperExpress.Request, res: HyperExpress.Response) => Promise<any>) {
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) {
Expand Down