From 18fc20ab4c3230098a186aa8d9d51da6df9b2298 Mon Sep 17 00:00:00 2001 From: Wilfredo Rujel <66637170+wrujel@users.noreply.github.com> Date: Fri, 20 May 2022 12:55:25 -0500 Subject: [PATCH] fix: adding documentation to create your own env file --- .gitignore | 6 +++++- README.md | 3 ++- backend/.env | 4 ---- backend/k8s/deployment.yaml | 41 ------------------------------------- backend/src/app.service.ts | 8 ++++---- backend/src/main.ts | 2 +- frontend/.env.local | 1 - frontend/.gitignore | 3 +++ frontend/pages/index.tsx | 2 +- 9 files changed, 16 insertions(+), 54 deletions(-) delete mode 100644 backend/.env delete mode 100644 backend/k8s/deployment.yaml delete mode 100644 frontend/.env.local diff --git a/.gitignore b/.gitignore index 2e1a787..86c3eb1 100644 --- a/.gitignore +++ b/.gitignore @@ -65,4 +65,8 @@ yarn-error.log* .vercel # typescript -*.tsbuildinfo \ No newline at end of file +*.tsbuildinfo + +# local env files +.env*.local +.env diff --git a/README.md b/README.md index a70c00b..17afebd 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,8 @@ We need now to get a personal token from your github account. 4) Type a note and click on `public repo`. 5) Click on Generate token. 6) Then copy token generated that start with `ghp_`. -7) Copy in file `.env`, after variable `API_TOKEN=`. +7) Create a new file name `.env` in folder `github-history/backend/` +8) Paste token in file `.env`, after variable `API_TOKEN=`. ### Running server Commands to run backend server, use `start:dev` if you want to automatically reset server after saving changes. diff --git a/backend/.env b/backend/.env deleted file mode 100644 index 363c467..0000000 --- a/backend/.env +++ /dev/null @@ -1,4 +0,0 @@ -PORT=8080 -API_USERS=https://api.github.com/users -API_REPOS=https://api.github.com/repos -API_TOKEN= \ No newline at end of file diff --git a/backend/k8s/deployment.yaml b/backend/k8s/deployment.yaml deleted file mode 100644 index 4a78a97..0000000 --- a/backend/k8s/deployment.yaml +++ /dev/null @@ -1,41 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: github-history -spec: - selector: - matchLabels: - app: github-history - replicas: 1 - template: - metadata: - labels: - app: github-history - spec: - containers: - - name: github-history - image: wrujel/github-history - ports: - - containerPort: 8080 - protocol: TCP - env: - - name: PORT - valueFrom: - secretKeyRef: - name: env-variables - key: PORT - - name: API_USERS - valueFrom: - secretKeyRef: - name: env-variables - key: API_USERS - - name: API_REPOS - valueFrom: - secretKeyRef: - name: env-variables - key: API_REPOS - - name: API_TOKEN - valueFrom: - secretKeyRef: - name: env-variables - key: API_TOKEN diff --git a/backend/src/app.service.ts b/backend/src/app.service.ts index ff23620..7dc64ac 100644 --- a/backend/src/app.service.ts +++ b/backend/src/app.service.ts @@ -13,7 +13,7 @@ export class AppService { }; getUser(user: string): Promise { - const userUrl = this.env.get('API_USERS'); + const userUrl = this.env.get('https://api.github.com/users'); return lastValueFrom( this.http.get(`${userUrl}/${user}`, { headers: this.header }).pipe( map((res) => res.data), @@ -27,7 +27,7 @@ export class AppService { } getRepos(user: string): Promise { - const userUrl = this.env.get('API_USERS'); + const userUrl = this.env.get('https://api.github.com/users'); return lastValueFrom( this.http .get(`${userUrl}/${user}/repos`, { headers: this.header }) @@ -43,7 +43,7 @@ export class AppService { } getBranches(user: string, repo: string): Promise { - const branchUrl = this.env.get('API_REPOS'); + const branchUrl = this.env.get('https://api.github.com/repos'); return lastValueFrom( this.http .get(`${branchUrl}/${user}/${repo}/branches`, { @@ -61,7 +61,7 @@ export class AppService { } getCommits(user: string, repo: string, branch: string): Promise { - const commitUrl = this.env.get('API_REPOS'); + const commitUrl = this.env.get('https://api.github.com/repos'); return lastValueFrom( this.http .get(`${commitUrl}/${user}/${repo}/commits?sha=${branch}`, { diff --git a/backend/src/main.ts b/backend/src/main.ts index ecb50d5..9eb890a 100644 --- a/backend/src/main.ts +++ b/backend/src/main.ts @@ -2,7 +2,7 @@ import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; -const PORT = process.env.PORT; +const PORT = process.env.PORT || 8080; async function bootstrap() { const app = await NestFactory.create(AppModule, { cors: true }); diff --git a/frontend/.env.local b/frontend/.env.local deleted file mode 100644 index 531f89d..0000000 --- a/frontend/.env.local +++ /dev/null @@ -1 +0,0 @@ -NEXT_PUBLIC_SERVER_URL = http://localhost:8080 \ No newline at end of file diff --git a/frontend/.gitignore b/frontend/.gitignore index 058d96e..81221e7 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -30,3 +30,6 @@ yarn-error.log* # typescript *.tsbuildinfo + +# local env files +.env*.local diff --git a/frontend/pages/index.tsx b/frontend/pages/index.tsx index 681fd55..a469ae6 100644 --- a/frontend/pages/index.tsx +++ b/frontend/pages/index.tsx @@ -5,7 +5,7 @@ import Image from "next/image"; import { useEffect, useState } from "react"; import styles from "../styles/Home.module.css"; -const serverUrl = process.env.NEXT_PUBLIC_SERVER_URL; +const serverUrl = process.env.NEXT_PUBLIC_SERVER_URL || "http://localhost:8080"; /** * Home Page