Skip to content

Commit ded7823

Browse files
committed
Add our IPFS & Ethereum extra API specs to the known API list
1 parent 9a1eda6 commit ded7823

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/model/api/api-store.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,36 @@ const apiMetadataSchema = serializr.createSimpleSchema({
4040
)
4141
});
4242

43+
// In addition to the public OpenAPI directory, we have a few extra APIs (stored in
44+
// this repo in /extra-apis) that we match seprately:
45+
const EXTRA_APIS: { [urlPrefix: string]: 'ipfs' | 'ethereum' } = {
46+
// See the 'servers' field in /extra-apis/ipfs.json:
47+
'localhost:5001/api/v0': 'ipfs',
48+
'127.0.0.1:5001/api/v0': 'ipfs',
49+
'ipfs.infura.io:5001/api/v0': 'ipfs',
50+
51+
// See the 'servers' field in /extra-apis/ethereum.json:
52+
'localhost:8545/': 'ethereum',
53+
'127.0.0.1:8545/': 'ethereum',
54+
'mainnet.infura.io/v3/': 'ethereum',
55+
'ropsten.infura.io/v3/': 'ethereum',
56+
'rinkeby.infura.io/v3/': 'ethereum',
57+
'kovan.infura.io/v3/': 'ethereum',
58+
'goerli.infura.io/v3/': 'ethereum'
59+
};
60+
61+
function findPublicApi(url: string) {
62+
const openApiId = findPublicOpenApi(url);
63+
64+
if (openApiId) return openApiId;
65+
66+
const matchingExtraApiKey = Object.keys(EXTRA_APIS)
67+
.find((apiPrefix) => url.startsWith(apiPrefix));
68+
69+
if (matchingExtraApiKey) return EXTRA_APIS[matchingExtraApiKey];
70+
else return undefined;
71+
}
72+
4373
export class ApiStore {
4474

4575
constructor(
@@ -156,7 +186,7 @@ export class ApiStore {
156186
// If not, is this a known public API? (note that private always has precedence)
157187
const requestUrl = `${parsedUrl.host}${parsedUrl.pathname}`;
158188

159-
let publicSpecId = findPublicOpenApi(requestUrl);
189+
let publicSpecId = findPublicApi(requestUrl);
160190
if (!publicSpecId) return;
161191
if (!Array.isArray(publicSpecId)) publicSpecId = [publicSpecId];
162192

0 commit comments

Comments
 (0)