thetatoken / theta-infrastructure-ledger-explorer

Explorer for the Theta Ledger
https://docs.thetatoken.org/
MIT License
57 stars 26 forks source link

Having issues with explorer api #20

Closed giovannirco closed 3 years ago

giovannirco commented 3 years ago

After getting the crawler working I proceeded to the api and I am having a few errors which is stopping the application before initializing

Loading config file: config.cfg
{
  mongo: {
    uri: 'mongodb://mongo_uri',
    port: 27017,
    dbName: 'theta_mainnet'
  },
  node: {
    address: 'theta-0.theta.coin-nodes.svc.cluster.local',
    port: 16888
  },
  log: { level: 'debug' },
  server: { port: 9000 },
  blockchain: { network_id: 'mainnet' },
  coinmarketcap: { key: 'COINMARKETCAP_API_KEY', theta_id: 2416, tfuel_id: 3822 },
  cert: { key: '', crt: '' },
  redis: {
    enabled: true,
    isCluster: false,
    host: 'redis-endpoint',
    port: 6379,
    family: 4,
    db: 0
  }
}
url is:  mongodb://mongo_uri
(node:24) [MONGODB DRIVER] Warning: Current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
connected to Redis
Mongo connection succeeded
/home/node/theta-infrastructure-ledger-explorer/backend/explorer-api/node_modules/mongodb/lib/topologies/server.js:294
          throw err;
          ^

Error: ENOENT: no such file or directory, open
    at Object.openSync (fs.js:462:3)
    at Object.readFileSync (fs.js:364:35)
    at /home/node/theta-infrastructure-ledger-explorer/backend/explorer-api/run.js:135:27
    at /home/node/theta-infrastructure-ledger-explorer/backend/mongo-db/mongo-client.js:35:5
    at /home/node/theta-infrastructure-ledger-explorer/backend/explorer-api/node_modules/mongodb/lib/utils.js:697:5
    at /home/node/theta-infrastructure-ledger-explorer/backend/explorer-api/node_modules/mongodb/lib/mongo_client.js:258:7
    at connectCallback (/home/node/theta-infrastructure-ledger-explorer/backend/explorer-api/node_modules/mongodb/lib/operations/connect.js:365:5)
    at /home/node/theta-infrastructure-ledger-explorer/backend/explorer-api/node_modules/mongodb/lib/operations/connect.js:458:5
    at Server.connectHandler (/home/node/theta-infrastructure-ledger-explorer/backend/explorer-api/node_modules/mongodb/lib/topologies/server.js:291:9)
    at Object.onceWrapper (events.js:421:26)
    at Server.emit (events.js:314:20)
    at Pool.<anonymous> (/home/node/theta-infrastructure-ledger-explorer/backend/explorer-api/node_modules/mongodb/lib/core/topologies/server.js:384:12)
    at Pool.emit (events.js:314:20)
    at /home/node/theta-infrastructure-ledger-explorer/backend/explorer-api/node_modules/mongodb/lib/core/connection/pool.js:581:12
    at /home/node/theta-infrastructure-ledger-explorer/backend/explorer-api/node_modules/mongodb/lib/core/connection/pool.js:1036:7
    at callback (/home/node/theta-infrastructure-ledger-explorer/backend/explorer-api/node_modules/mongodb/lib/core/connection/connect.js:75:5) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT'
}

I suspect the issue might be related to the recent changes on the MongoDB driver made on the crawler.

I am using a super simple Dockerfile to just git clone the repo and run npm install at the correct directory and using a start script as an entry point of the docker image to run the app (node run &) and handle sigs issued by kubernetes, just something we usually do around here with the applications we run and works fine for crawler.

FROM our-own-node12-image

ENV VERSION=8dfa1979b7eb945cb88086b031a99a5be19d1640

WORKDIR /home/node/

RUN set -ex && \
    yum groupinstall "Development Tools" -y && \
    yum install git -y && \
    git clone https://github.com/thetatoken/theta-infrastructure-ledger-explorer.git && \
    cd theta-infrastructure-ledger-explorer && \
    git checkout $VERSION && \
    cd backend/explorer-api && \
    npm install && \
    yum groupremove "Development Tools" -y && \
    chown node:node -R /home/node

# Our script to run via kubernetes to start script with options from env vars and handle sigs
COPY entrypoint.sh /usr/local/bin/start-script.sh
RUN chmod a+x /usr/local/bin/start-script.sh

USER node
WORKDIR /home/node/theta-infrastructure-ledger-explorer/backend/explorer-api

ENTRYPOINT ["/bin/bash", "/usr/local/bin/start-script.sh"]

About the config file, what does this do?

  cert: { key: '', crt: '' },

And do I need a CMC api key? or is this just for the frontend?

zhenyang-sliver commented 3 years ago

The error is related to the certificate you mentioned in the config file, for a https website, you need a certificate. This part of config is where you can put the path of the cert files. In the latest code, I changed it to disable by default.

For the CMC api key, if you don't use the price related APIs, then you don't need it.

giovannirco commented 3 years ago

Ahh gotcha, thanks for explaining what was the error. I have tried running your commit and although the application starts I wasn't able to fetch information from the web server. I took a deeper look today with the help of a friend and the problem lies on the fact that the server was still using https although we didn't offer any certs or keys and I ended up with an empty reply every time I queried it. I have forked the repo and did a couple of changes needed and now I have the api running smoothly on my env. I created the PR #22 but it only uses HTTP instead of HTTPS which is not ideal so we may need an option to toggle between http or https.

giovannirco commented 3 years ago

The PR #24 fixes my issue and also handle the option between HTTP and HTTPS just fine. Can I get it reviewed and possibly merged please?

giovannirco commented 3 years ago

Fixed available on master branch. Thanks.