Skip to content

Commit

Permalink
env: prod / dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ceddybi committed Mar 5, 2024
1 parent 89995f9 commit 8b7b6be
Show file tree
Hide file tree
Showing 5 changed files with 492 additions and 332 deletions.
25 changes: 14 additions & 11 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
// api with axios

import axios, { AxiosInstance } from 'axios';
import { getResume, getState, setState } from "../utils/state";

import _get from "lodash/get";
import axios from 'axios';
import { isEmpty } from "lodash";

export const isDev = process.env.APP_DEV ? (process.env.APP_DEV.trim() == "true") : false;
export const getBaseUrl = (isDev: boolean) => {
return isDev ? "http://localhost:3001" : "https://www.algojobs.ca";
};

export const baseURL = isDev ? "http://localhost:3001" : "https://www.algojobs.ca";
const api = axios.create({
baseURL,
});
export const getApiInstance = (isDev: boolean): AxiosInstance => {
const baseURL = getBaseUrl(isDev);
return axios.create({
baseURL,
});
};

interface IResponse {
status: number;
// data: any;
};


interface GetAuth {
access_token: string;
refresh_token: string;
Expand All @@ -33,6 +35,7 @@ interface GetAuthApiRes {

export const getAuthApi = async (args: GetAuth): Promise<any> => {
let state = await getState();
const api = getApiInstance(state.dev || false);
try {
const response = await api.post<GetAuthApiRes>('/api/auth', args);
if (response.status !== 200) {
Expand Down Expand Up @@ -80,6 +83,7 @@ interface IMainResponse extends IResponse {
export const getMainApi = async (): Promise<any> => {
try {
const state = await getState();
const api = getApiInstance(state.dev || false);
const resume = await getResume();
const access_token = _get(state, "auth.access_token");
const refresh_token = _get(state, "auth.refresh_token");
Expand Down Expand Up @@ -122,6 +126,7 @@ export const getMainApi = async (): Promise<any> => {
export const getAppApi = async (): Promise<any> => {
try {
const state = await getState();
const api = getApiInstance(state.dev || false);
const resume = await getResume();
const access_token = _get(state, "auth.access_token");
const refresh_token = _get(state, "auth.refresh_token");
Expand Down Expand Up @@ -170,6 +175,4 @@ export const getAppApi = async (): Promise<any> => {
// questions,
// resume sections,

// settings

export default api;
// settings
Loading

0 comments on commit 8b7b6be

Please sign in to comment.