Skip to content

Commit

Permalink
Merge pull request #24 from forbole/refactor-env
Browse files Browse the repository at this point in the history
chore: update env and remove endpoint
  • Loading branch information
icfor authored Nov 21, 2023
2 parents aa9bd26 + 058fe1c commit dc937ef
Show file tree
Hide file tree
Showing 17 changed files with 2,353 additions and 6,011 deletions.
5 changes: 3 additions & 2 deletions .env.defaults
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PUBLIC_URL=http://localhost:4000
NODE_ENV=development
MAX_OVER_TIME_DURATION=2d
NODE_ENV=development
PROMETHEUS_URL=...
RADIX_URL=...
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ ENV NODE_ENV=production
RUN npm install
COPY --from=builer /app/dist ./dist
RUN npm install pm2 -g
CMD ["pm2-runtime", "dist/src/index.js"]
CMD ["pm2-runtime", "dist/index.js"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ In **production** environments, when `NODE_ENV` is `production`, users can query

##### Querying total no. of users staked to Forbole on all Cosmos SDK chains:

```zsh
```bash
curl --request POST \
--header 'content-type: application/json' \
--url https://api.forbole.com/graphql \
Expand Down
12 changes: 0 additions & 12 deletions jest.config.js

This file was deleted.

8,193 changes: 2,328 additions & 5,865 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 3 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"build": "rm -rf dist && tsc",
"dev": "NODE_ENV=development nodemon",
"lint": "eslint . --ext .ts && prettier './**/*.{ts,js}' --check",
"start": "NODE_ENV=production node dist/src/index.js",
"test": "NODE_ENV=test jest"
"start": "NODE_ENV=production node dist/index.js",
"test": "echo No tests"
},
"keywords": [],
"author": "",
Expand All @@ -21,16 +21,13 @@
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"express": "^4.17.1",
"graphql": "^16.6.0",
"nodemailer": "^6.7.2"
"graphql": "^16.6.0"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/cors": "^2.8.12",
"@types/express": "^4.17.13",
"@types/jest": "^29.5.8",
"@types/node": "^20.9.2",
"@types/nodemailer": "^6.4.4",
"@typescript-eslint/eslint-plugin": "^6.11.0",
"@typescript-eslint/parser": "^6.11.0",
"eslint": "^8.3.0",
Expand All @@ -39,10 +36,8 @@
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-prettier": "^5.0.1",
"jest": "^29.7.0",
"nodemon": "^3.0.1",
"prettier": "^3.1.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.7.0",
"typescript": "^5.2.2"
}
Expand Down
26 changes: 0 additions & 26 deletions src/controllers/common/contact.test.ts

This file was deleted.

35 changes: 0 additions & 35 deletions src/controllers/common/contact.ts

This file was deleted.

9 changes: 0 additions & 9 deletions src/controllers/common/index.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/controllers/index.ts

This file was deleted.

7 changes: 1 addition & 6 deletions src/graphql/resolvers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,7 @@ export const resolvers = {
__: any,
{ dataSources }: ContextValue,
) => {
const JSONbody = {
network_identifier: {
network: "mainnet",
},
};
const response = await dataSources.radixAPI.getTotalRadixSupply(JSONbody);
const response = await dataSources.radixAPI.getTotalRadixSupply();
const { token } = response;
const { token_supply } = token;
const val = {
Expand Down
16 changes: 13 additions & 3 deletions src/graphql/routes/radix-api.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
import { RESTDataSource } from "@apollo/datasource-rest";
import type { KeyValueCache } from "@apollo/utils.keyvaluecache";

const { RADIX_URL } = process.env;

if (!RADIX_URL) {
throw new Error("Missing RADIX_URL env var");
}

export class RadixAPI extends RESTDataSource {
override baseURL = `${process.env.RADIX_URL}/`;
override baseURL = `${(RADIX_URL as string).replace(/\/$/, "")}/`;

constructor(options: { cache: KeyValueCache }) {
super(options); // this sends our server's `cache` through
}

async getTotalRadixSupply(body: any) {
async getTotalRadixSupply() {
return this.post("token/native", {
headers: {
"Content-Type": "application/json",
},
body,
body: JSON.stringify({
network_identifier: {
network: "mainnet",
},
}),
});
}

Expand Down
11 changes: 3 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ import {
} from "./graphql/routes";
import { typeDefs } from "./graphql/typedefs";
import type { ContextValue } from "./graphql/types";
import { v1 } from "./routers";

require("dotenv").config();

(async () => {
const app = express();
const httpServer = http.createServer(app);
const port = process.env.PORT || 4000;

// Set up Apollo Server
const server = new ApolloServer({
typeDefs,
resolvers,
Expand All @@ -38,8 +37,6 @@ require("dotenv").config();

app.use(cors());

app.use("/api/v1/", v1);

app.use(
"/graphql",
cors<cors.CorsRequest>(),
Expand Down Expand Up @@ -98,9 +95,7 @@ require("dotenv").config();
},
);

await new Promise<void>((resolve) =>
httpServer.listen({ port: 4000 }, resolve),
);
await new Promise<void>((resolve) => httpServer.listen({ port }, resolve));

console.log(`🚀 Server ready at http://localhost:4000/graphql`);
console.log(`🚀 Server ready at http://localhost:${port}/graphql`);
})();
3 changes: 0 additions & 3 deletions src/routers/index.ts

This file was deleted.

9 changes: 0 additions & 9 deletions src/routers/v1/common.ts

This file was deleted.

9 changes: 0 additions & 9 deletions src/routers/v1/index.ts

This file was deleted.

11 changes: 0 additions & 11 deletions tests/express_mock.ts

This file was deleted.

0 comments on commit dc937ef

Please sign in to comment.