Skip to content

Commit 2620292

Browse files
committed
fix: dev env
1 parent c8d60fc commit 2620292

File tree

3 files changed

+40
-29
lines changed

3 files changed

+40
-29
lines changed

backend/pkd/controller/basecontroller.go

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,29 @@ import (
2828
)
2929

3030
func Start(embeddedFiles fs.FS) {
31+
apiBase := "/api"
3132
router := gin.Default()
3233
router.Use(gzip.Gzip(gzip.DefaultCompression))
33-
router.POST("/appuser/signin", postSignin)
34-
router.POST("/appuser/login", postLogin)
35-
router.GET("/appuser/logout", token.CheckToken, getLogout)
36-
router.GET("/appuser/location", token.CheckToken, getLocation)
37-
router.GET("/appuser/refreshtoken", token.CheckToken, getRefreshToken)
38-
router.POST("/appuser/locationradius", token.CheckToken, postUserLocationRadius)
39-
router.POST("/appuser/targetprices", token.CheckToken, postTargetPrices)
40-
router.GET("/config/updategs", token.CheckToken, gsclient.UpdateGasStations)
41-
router.GET("/config/updatepc", token.CheckToken, getPostCodeCoordinates)
42-
router.GET("/config/updatestatescounties", token.CheckToken, getStateCountyData)
43-
router.GET("/config/recalcAvgs", token.CheckToken, getRecalcAvgs)
44-
router.GET("/gasprice/:id", token.CheckToken, getGasPriceByGasStationId)
45-
router.GET("/gasstation/:id", token.CheckToken, getGasStationById)
46-
router.GET("/gasprice/avgs/:postcode", token.CheckToken, getAveragePrices)
47-
router.POST("/gasstation/search/place", token.CheckToken, searchGasStationPlace)
48-
router.POST("/gasstation/search/location", token.CheckToken, searchGasStationLocation)
49-
router.GET("/usernotification/new/:useruuid", token.CheckToken, getNewUserNotifications)
50-
router.GET("/usernotification/current/:useruuid", token.CheckToken, getCurrentUserNotifications)
51-
router.GET("/postcode/countytimeslots/:postcode", token.CheckToken, getCountyDataByIdWithTimeSlots)
52-
router.GET("/gasstation/countytimeslots/recalc", token.CheckToken, getRecalcTimeSlots)
34+
router.POST(apiBase+"/appuser/signin", postSignin)
35+
router.POST(apiBase+"/appuser/login", postLogin)
36+
router.GET(apiBase+"/appuser/logout", token.CheckToken, getLogout)
37+
router.GET(apiBase+"/appuser/location", token.CheckToken, getLocation)
38+
router.GET(apiBase+"/appuser/refreshtoken", token.CheckToken, getRefreshToken)
39+
router.POST(apiBase+"/appuser/locationradius", token.CheckToken, postUserLocationRadius)
40+
router.POST(apiBase+"/appuser/targetprices", token.CheckToken, postTargetPrices)
41+
router.GET(apiBase+"/config/updategs", token.CheckToken, gsclient.UpdateGasStations)
42+
router.GET(apiBase+"/config/updatepc", token.CheckToken, getPostCodeCoordinates)
43+
router.GET(apiBase+"/config/updatestatescounties", token.CheckToken, getStateCountyData)
44+
router.GET(apiBase+"/config/recalcAvgs", token.CheckToken, getRecalcAvgs)
45+
router.GET(apiBase+"/gasprice/:id", token.CheckToken, getGasPriceByGasStationId)
46+
router.GET(apiBase+"/gasstation/:id", token.CheckToken, getGasStationById)
47+
router.GET(apiBase+"/gasprice/avgs/:postcode", token.CheckToken, getAveragePrices)
48+
router.POST(apiBase+"/gasstation/search/place", token.CheckToken, searchGasStationPlace)
49+
router.POST(apiBase+"/gasstation/search/location", token.CheckToken, searchGasStationLocation)
50+
router.GET(apiBase+"/usernotification/new/:useruuid", token.CheckToken, getNewUserNotifications)
51+
router.GET(apiBase+"/usernotification/current/:useruuid", token.CheckToken, getCurrentUserNotifications)
52+
router.GET(apiBase+"/postcode/countytimeslots/:postcode", token.CheckToken, getCountyDataByIdWithTimeSlots)
53+
router.GET(apiBase+"/gasstation/countytimeslots/recalc", token.CheckToken, getRecalcTimeSlots)
5354

5455
myPort := strings.TrimSpace(os.Getenv("PORT"))
5556
portNum, err := strconv.ParseInt(myPort, 10, 0)

frontend/app/service/http-client.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const fetchGasStations = async function (jwtToken: string, controller: AbortCont
2525
body: JSON.stringify({ Longitude: globalUserDataState.Longitude, Latitude: globalUserDataState.Latitude, Radius: globalUserDataState.SearchRadius }),
2626
signal: controller?.signal
2727
}
28-
const result = await fetch('/gasstation/search/location', requestOptions2);
28+
const result = await fetch('/api/gasstation/search/location', requestOptions2);
2929
const myResult = result.json() as Promise<GasStation[]>;
3030
return myResult;
3131
};
@@ -36,7 +36,7 @@ const fetchPriceAvgs = async function (jwtToken: string, controller: AbortContro
3636
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${jwtToken}` },
3737
signal: controller?.signal
3838
}
39-
const result = await fetch(`/gasprice/avgs/${myPostcode}`, requestOptions3);
39+
const result = await fetch(`/api/gasprice/avgs/${myPostcode}`, requestOptions3);
4040
return result.json() as Promise<GasPriceAvgs>;
4141
}
4242

@@ -46,7 +46,7 @@ const fetchUserNotifications = async function (jwtToken: string, controller: Abo
4646
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${jwtToken}` },
4747
signal: controller?.signal
4848
}
49-
const result = await fetch(`/usernotification/current/${globalUserUuidState}`, requestOptions1);
49+
const result = await fetch(`/api/usernotification/current/${globalUserUuidState}`, requestOptions1);
5050
return result.json() as Promise<Notification[]>;
5151
}
5252

@@ -56,20 +56,20 @@ const fetchTimeSlots = async function (jwtToken: string, controller: AbortContro
5656
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${jwtToken}` },
5757
signal: controller?.signal
5858
}
59-
const result = await fetch(`/postcode/countytimeslots/${myPostcode}`, requestOptions2);
59+
const result = await fetch(`/api/postcode/countytimeslots/${myPostcode}`, requestOptions2);
6060
const myResult = result.json() as Promise<TimeSlotResponse[]>;
6161
return myResult;
6262
}
6363

6464
const postLogin = async function (userName: string, password1: string, controller: AbortController | null): Promise<UserResponse> {
6565
const requestOptions = loginSigninOptions(userName, password1, controller);
66-
const result = await fetch('/appuser/login', requestOptions);
66+
const result = await fetch('/api/appuser/login', requestOptions);
6767
return result.json() as Promise<UserResponse>;
6868
}
6969

7070
const postSignin = async function (userName: string, password1: string, controller: AbortController | null): Promise<UserResponse> {
7171
const requestOptions = loginSigninOptions(userName, password1, controller);
72-
const result = await fetch('/appuser/signin', requestOptions);
72+
const result = await fetch('/api/appuser/signin', requestOptions);
7373
return result.json() as Promise<UserResponse>;
7474
}
7575

@@ -89,7 +89,7 @@ const postLocationRadius = async function (jwtToken: string, controller: AbortCo
8989
body: requestString,
9090
signal: controller?.signal
9191
};
92-
const response = await fetch('/appuser/locationradius', requestOptions);
92+
const response = await fetch('/api/appuser/locationradius', requestOptions);
9393
const userResponse = response.json() as UserResponse;
9494
return userResponse;
9595
}
@@ -100,7 +100,7 @@ const fetchLocation = async function (jwtToken: string, controller: AbortControl
100100
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${jwtToken}` },
101101
signal: controller?.signal
102102
};
103-
const response = await fetch(`/appuser/location?location=${location}`, requestOptions);
103+
const response = await fetch(`/api/appuser/location?location=${location}`, requestOptions);
104104
const locations = response.json() as Promise<PostCodeLocation[]>;
105105
return locations;
106106
}
@@ -112,7 +112,7 @@ const postTargetPrices = async function (jwtToken: string, controller: AbortCont
112112
body: requestString,
113113
signal: controller?.signal
114114
};
115-
const response = await fetch('/appuser/targetprices', requestOptions);
115+
const response = await fetch('/api/appuser/targetprices', requestOptions);
116116
const result = response.json() as Promise<UserResponse>;
117117
return result;
118118
}

frontend/vite.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,14 @@ import tsconfigPaths from "vite-tsconfig-paths";
1717

1818
export default defineConfig({
1919
plugins: [tailwindcss(), reactRouter(), tsconfigPaths()],
20+
server: {
21+
proxy: {
22+
// Proxy all requests starting with /api to http://localhost:3000
23+
'/api': {
24+
target: 'http://localhost:3000',
25+
changeOrigin: true,
26+
//rewrite: (path) => path.replace(/^\/api/, ''), // remove /api prefix
27+
},
28+
},
29+
},
2030
});

0 commit comments

Comments
 (0)