Skip to content

Commit 3b15a98

Browse files
Revert "Merge pull request #236 from CodeForPhilly/refactor-authFetch"
This reverts commit bb7fe22, reversing changes made to afc9421.
1 parent bb7fe22 commit 3b15a98

File tree

7 files changed

+56
-70
lines changed

7 files changed

+56
-70
lines changed

builder-frontend/.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
VITE_API_KEY=AIzaSyDummyKeyForEmulator
2-
VITE_API_URL=http://localhost:8081/
2+
VITE_API_URL=http://localhost:8081/api
33
VITE_APP_ID=1:123456789:web:abcdef
44
VITE_AUTH_DOMAIN=localhost:9099
55
VITE_MEASUREMENT_ID=G-XXXXXXXXXX
66
VITE_MESSAGING_SENDER_ID=123456789
77
VITE_PROJECT_ID=demo-bdt-dev
8+
VITE_SCREENER_BASE_URL=http://localhost:5174/
89
VITE_STORAGE_BUCKET=demo-bdt-dev.appspot.com
910
DEV_SERVER_PORT=5173

builder-frontend/src/api/benefit.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import BenefitList from "@/components/project/manageBenefits/benefitList/Benefit
33

44
import { Benefit } from "@/types";
55

6+
const apiUrl = import.meta.env.VITE_API_URL;
7+
68
export const fetchScreenerBenefit = async (
79
srceenerId: string,
810
benefitId: string
911
): Promise<Benefit> => {
10-
const url = `/api/screener/${srceenerId}/benefit/${benefitId}`;
12+
const url = apiUrl + "/screener/" + srceenerId + "/benefit/" + benefitId;
1113
try {
1214
const response = await authFetch(url, {
1315
method: "GET",
@@ -31,7 +33,7 @@ export const updateScreenerBenefit = async (
3133
screenerId: string,
3234
benefitData: Benefit
3335
): Promise<Benefit> => {
34-
const url = `/api/screener/${screenerId}/benefit`;
36+
const url = apiUrl + "/screener/" + screenerId + "/benefit";
3537
try {
3638
const response = await authFetch(url, {
3739
method: "PUT",
@@ -54,7 +56,7 @@ export const updateScreenerBenefit = async (
5456
};
5557

5658
export const fetchPublicBenefits = async (): Promise<Benefit[]> => {
57-
const url = "/api/benefit";
59+
const url = apiUrl + "/benefit";
5860
try {
5961
const response = await authFetch(url, {
6062
method: "GET",

builder-frontend/src/api/check.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { authFetch } from "@/api/auth";
22

33
import type { EligibilityCheck, OptionalBoolean } from "@/types";
44

5+
const apiUrl = import.meta.env.VITE_API_URL;
6+
57
export const fetchPublicChecks = async (): Promise<EligibilityCheck[]> => {
6-
const url = "/api/library-checks";
8+
const url = apiUrl + "/library-checks";
79
try {
810
const response = await authFetch(url, {
911
method: "GET",
@@ -27,8 +29,10 @@ export const fetchPublicChecks = async (): Promise<EligibilityCheck[]> => {
2729
export const fetchCheck = async (
2830
checkId: string
2931
): Promise<EligibilityCheck> => {
30-
const checkResource = checkId[0] === "L" ? "library-checks" : "custom-checks";
31-
const url = `/api/${checkResource}/${checkId}`;
32+
let url = apiUrl + `/custom-checks/${checkId}`;
33+
if (checkId.charAt(0) === "L") {
34+
url = apiUrl + `/library-checks/${checkId}`;
35+
}
3236

3337
try {
3438
const response = await authFetch(url, {
@@ -51,7 +55,7 @@ export const fetchCheck = async (
5155
};
5256

5357
export const addCheck = async (check: EligibilityCheck) => {
54-
const url = "/api/custom-checks";
58+
const url = apiUrl + "/custom-checks";
5559
try {
5660
const response = await authFetch(url, {
5761
method: "POST",
@@ -74,7 +78,7 @@ export const addCheck = async (check: EligibilityCheck) => {
7478
};
7579

7680
export const updateCheck = async (check: EligibilityCheck) => {
77-
const url = "/api/custom-checks";
81+
const url = apiUrl + "/custom-checks";
7882
try {
7983
const response = await authFetch(url, {
8084
method: "PUT",
@@ -97,7 +101,7 @@ export const updateCheck = async (check: EligibilityCheck) => {
97101
};
98102

99103
export const saveCheckDmn = async (checkId: string, dmnModel: string) => {
100-
const url = "/api/save-check-dmn";
104+
const url = apiUrl + "/save-check-dmn";
101105
try {
102106
const response = await authFetch(url, {
103107
method: "POST",
@@ -121,7 +125,7 @@ export const validateCheckDmn = async (
121125
checkId: string,
122126
dmnModel: string
123127
): Promise<string[]> => {
124-
const url = "/api/validate-check-dmn";
128+
const url = apiUrl + "/validate-check-dmn";
125129
try {
126130
const response = await authFetch(url, {
127131
method: "POST",
@@ -147,7 +151,8 @@ export const validateCheckDmn = async (
147151
export const fetchUserDefinedChecks = async (
148152
working: boolean
149153
): Promise<EligibilityCheck[]> => {
150-
const url = `/api/custom-checks?working=${working}`;
154+
const workingQueryParam = working ? "true" : "false";
155+
let url: string = apiUrl + `/custom-checks?working=${workingQueryParam}`;
151156

152157
try {
153158
const response = await authFetch(url, {
@@ -173,7 +178,7 @@ export const evaluateWorkingCheck = async (
173178
checkConfig: any,
174179
inputData: Record<string, any>
175180
): Promise<OptionalBoolean> => {
176-
const url = `/api/decision/working-check?checkId=${checkId}`;
181+
const url = apiUrl + `/decision/working-check?checkId=${checkId}`;
177182
try {
178183
const response = await authFetch(url, {
179184
method: "POST",
@@ -198,7 +203,7 @@ export const evaluateWorkingCheck = async (
198203
export const getRelatedPublishedChecks = async (
199204
checkId: string
200205
): Promise<EligibilityCheck[]> => {
201-
const url = `/api/custom-checks/${checkId}/published-check-versions`;
206+
const url = apiUrl + `/custom-checks/${checkId}/published-check-versions`;
202207
try {
203208
const response = await authFetch(url, {
204209
method: "GET",
@@ -221,7 +226,7 @@ export const getRelatedPublishedChecks = async (
221226
export const publishCheck = async (
222227
checkId: string
223228
): Promise<OptionalBoolean> => {
224-
const url = `/api/publish-check/${checkId}`;
229+
const url = apiUrl + `/publish-check/${checkId}`;
225230
try {
226231
const response = await authFetch(url, {
227232
method: "POST",
@@ -242,7 +247,7 @@ export const publishCheck = async (
242247
};
243248

244249
export const archiveCheck = async (checkId: string): Promise<void> => {
245-
const url = `/api/custom-checks/${checkId}/archive`;
250+
const url = apiUrl + `/custom-checks/${checkId}/archive`;
246251
try {
247252
const response = await authFetch(url, {
248253
method: "POST",

builder-frontend/src/api/publishedScreener.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { PublishedScreener, ScreenerResult } from "@/types";
22

3-
export const fetchPublishedScreener = async (
4-
publishedScreenerId: string
5-
): Promise<PublishedScreener> => {
6-
const url = `/api/published/screener/${publishedScreenerId}`;
3+
const apiUrl = import.meta.env.VITE_API_URL;
4+
5+
export const fetchPublishedScreener = async (publishedScreenerId: string): Promise<PublishedScreener> => {
6+
const url = apiUrl + "/published/screener/" + publishedScreenerId;
77
try {
88
const response = await fetch(url, {
99
method: "GET",
@@ -23,11 +23,9 @@ export const fetchPublishedScreener = async (
2323
}
2424
};
2525

26-
export const evaluatePublishedScreener = async (
27-
publishedScreenerId: string,
28-
inputData: any
29-
): Promise<ScreenerResult> => {
30-
const url = `/published/${publishedScreenerId}/evaluate`;
26+
27+
export const evaluatePublishedScreener = async (publishedScreenerId: string, inputData: any): Promise<ScreenerResult> => {
28+
const url = apiUrl + "/published/" + publishedScreenerId + "/evaluate";
3129
try {
3230
const response = await fetch(url, {
3331
method: "POST",

builder-frontend/src/api/screener.ts

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { authFetch } from "@/api/auth";
22

33
import type { BenefitDetail, ScreenerResult } from "@/types";
44

5+
const apiUrl = import.meta.env.VITE_API_URL;
6+
57
export const fetchProjects = async () => {
6-
const url = "/api/screeners";
8+
const url = apiUrl + "/screeners";
79
try {
810
const response = await authFetch(url, {
911
method: "GET",
@@ -23,8 +25,8 @@ export const fetchProjects = async () => {
2325
}
2426
};
2527

26-
export const fetchProject = async (screenerId: string) => {
27-
const url = `/api/screener/${screenerId}`;
28+
export const fetchProject = async (screenerId) => {
29+
const url = apiUrl + "/screener/" + screenerId;
2830
try {
2931
const response = await authFetch(url, {
3032
method: "GET",
@@ -45,7 +47,7 @@ export const fetchProject = async (screenerId: string) => {
4547
};
4648

4749
export const createNewScreener = async (screenerData) => {
48-
const url = "/api/screener";
50+
const url = apiUrl + "/screener";
4951
try {
5052
const response = await authFetch(url, {
5153
method: "POST",
@@ -68,7 +70,7 @@ export const createNewScreener = async (screenerData) => {
6870
};
6971

7072
export const updateScreener = async (screenerData) => {
71-
const url = "/api/screener";
73+
const url = apiUrl + "/screener";
7274
try {
7375
const response = await authFetch(url, {
7476
method: "PUT",
@@ -89,7 +91,7 @@ export const updateScreener = async (screenerData) => {
8991
};
9092

9193
export const deleteScreener = async (screenerData) => {
92-
const url = "/api/screener/delete?screenerId=" + screenerData.id;
94+
const url = apiUrl + "/screener/delete?screenerId=" + screenerData.id;
9395
try {
9496
const response = await authFetch(url, {
9597
method: "DELETE",
@@ -112,7 +114,7 @@ export const saveFormSchema = async (screenerId, schema) => {
112114
const requestData: any = {};
113115
requestData.screenerId = screenerId;
114116
requestData.schema = schema;
115-
const url = "/api/save-form-schema";
117+
const url = apiUrl + "/save-form-schema";
116118
try {
117119
const response = await authFetch(url, {
118120
method: "POST",
@@ -133,7 +135,7 @@ export const saveFormSchema = async (screenerId, schema) => {
133135
};
134136

135137
export const publishScreener = async (screenerId: string): Promise<void> => {
136-
const url = "/api/publish";
138+
const url = apiUrl + "/publish";
137139
try {
138140
const response = await authFetch(url, {
139141
method: "POST",
@@ -153,11 +155,8 @@ export const publishScreener = async (screenerId: string): Promise<void> => {
153155
}
154156
};
155157

156-
export const addCustomBenefit = async (
157-
screenerId: string,
158-
benefit: BenefitDetail
159-
) => {
160-
const url = `/api/screener/${screenerId}/benefit`;
158+
export const addCustomBenefit = async (screenerId: string, benefit: BenefitDetail) => {
159+
const url = apiUrl + "/screener/" + screenerId + "/benefit";
161160
try {
162161
const response = await authFetch(url, {
163162
method: "POST",
@@ -177,11 +176,8 @@ export const addCustomBenefit = async (
177176
}
178177
};
179178

180-
export const removeCustomBenefit = async (
181-
screenerId: string,
182-
benefitId: string
183-
) => {
184-
const url = `/screener/${screenerId}/benefit/${benefitId}`;
179+
export const removeCustomBenefit = async (screenerId: string, benefitId: string) => {
180+
const url = apiUrl + "/screener/" + screenerId + "/benefit/" + benefitId;
185181
try {
186182
const response = await authFetch(url, {
187183
method: "DELETE",
@@ -192,21 +188,16 @@ export const removeCustomBenefit = async (
192188
});
193189

194190
if (!response.ok) {
195-
throw new Error(
196-
`Delete of benefit failed with status: ${response.status}`
197-
);
191+
throw new Error(`Delete of benefit failed with status: ${response.status}`);
198192
}
199193
} catch (error) {
200194
console.error("Error deleting custom benefit:", error);
201195
throw error;
202196
}
203197
};
204198

205-
export const evaluateScreener = async (
206-
screenerId: string,
207-
inputData: any
208-
): Promise<ScreenerResult> => {
209-
const url = `/api/decision/v2?screenerId=${screenerId}`;
199+
export const evaluateScreener = async (screenerId: string, inputData: any): Promise<ScreenerResult> => {
200+
const url = apiUrl + "/decision/v2?screenerId=" + screenerId;
210201
try {
211202
const response = await authFetch(url, {
212203
method: "POST",
@@ -220,7 +211,7 @@ export const evaluateScreener = async (
220211
if (!response.ok) {
221212
throw new Error(`Evaluation failed with status: ${response.status}`);
222213
}
223-
214+
224215
const data = await response.json();
225216
return data;
226217
} catch (error) {

builder-frontend/vite.config.js

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
1-
import { defineConfig, loadEnv } from "vite";
1+
import { defineConfig } from "vite";
22
import solid from "vite-plugin-solid";
3-
import tsconfigPaths from "vite-tsconfig-paths";
3+
import tsconfigPaths from 'vite-tsconfig-paths'
44

5-
export default defineConfig(({ mode }) => {
6-
// Load variables from .env before vite.config.js finishes running
7-
const env = loadEnv(mode, process.cwd(), "");
8-
return {
9-
plugins: [solid(), tsconfigPaths()],
10-
server: {
11-
port: env.DEV_SERVER_PORT || 5173,
12-
// Proxy to connect to backend
13-
// https://vite.dev/config/server-options#server-proxy
14-
proxy: {
15-
"/api": {
16-
target: env.VITE_API_URL || "http://localhost:8081",
17-
},
18-
},
19-
},
20-
};
5+
export default defineConfig({
6+
plugins: [solid(), tsconfigPaths()],
7+
server: {
8+
port: process.env.DEV_SERVER_PORT || 5173
9+
}
2110
});

0 commit comments

Comments
 (0)