Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make the endpoint localhost or aedes based on development environment #194

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/client/src/contexts/LapDataContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {

import { CONNECTIONTYPES, useAppState } from "@/contexts/AppStateContext";
import { socketIO } from "@/contexts/SocketContext";
import { prodURL } from "@shared/helios-types";
import { IFormattedLapData, ILapData } from "@shared/helios-types";

interface ILapDataContextReturn {
Expand Down Expand Up @@ -47,9 +48,7 @@ export function LapDataContextProvider({

const fetchLapData = useCallback(async () => {
try {
const response = await axios.get(
`https://aedes.calgarysolarcar.ca:3001/laps`,
);
const response = await axios.get(`${prodURL}/laps`);
return response.data; // Assuming the API returns an array of lap data
} catch (error) {
return { error: "Error fetching lap data" };
Expand Down
8 changes: 2 additions & 6 deletions packages/client/src/contexts/SocketContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { type Socket, io } from "socket.io-client";

import { useAppState } from "@/contexts/AppStateContext";
import { prodFlag } from "@shared/helios-types";
import type {
CoordInfoUpdate,
CoordUpdateResponse,
Expand All @@ -30,14 +31,9 @@ interface ServerToClientEvents {
lapData: (value: ILapData) => void;
}

const URL =
process.env.NODE_ENV === "production"
? "aedes.calgarysolarcar.ca:3001"
: "http://localhost:3001";

// Defaults to using client fakerJS, change Data to Network in site settings to connect to server
export const socketIO: Socket<ServerToClientEvents, ClientToServerEvents> = io(
URL,
prodFlag,
{ autoConnect: false },
);

Expand Down
20 changes: 5 additions & 15 deletions packages/client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,9 @@
"checkJs": true,
"baseUrl": ".",
"paths": {
"plotly.js-dist-min": [
"node_modules/@types/plotly.js"
],
"@/*": [
"./src/*",
"./public/*",
],
"@/server/*": [
"../server/src/*"
]
"plotly.js-dist-min": ["node_modules/@types/plotly.js"],
"@/*": ["./src/*", "./public/*"],
"@/server/*": ["../server/src/*"]
},
"jsx": "preserve"
},
Expand All @@ -25,8 +18,5 @@
"**/*.cjs",
"**/*.mjs"
],
"exclude": [
"node_modules",
"tailwind.config.ts"
]
}
"exclude": ["node_modules", "tailwind.config.ts"]
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import type { MqttClient } from "mqtt";
import type { IClientOptions } from "mqtt/*";

import { prodFlag } from "@shared/helios-types";

export const options: IClientOptions = {
host:
process.env.NODE_ENV === "development"
? "localhost"
: "aedes.calgarysolarcar.ca",
host: prodFlag,
password: process.env.MQTT_PASSWORD,
port: 1883,
protocol: "tcp",
protocolVersion: 3,
username: process.env.MQTT_USERNAME,
password: process.env.MQTT_PASSWORD,
};

export const topics = {
Expand Down
1 change: 1 addition & 0 deletions packages/shared/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./src/types";
export * from "./src/functions";
export * from "./src/vehicleVelocity";
export * from "./src/prodFlag";
9 changes: 9 additions & 0 deletions packages/shared/src/prodFlag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const prodFlag =
process.env.NODE_ENV === "production"
? "aedes.calgarysolarcar.ca:3001"
: "http://localhost:3001";

export const prodURL =
process.env.NODE_ENV === "production"
? "https://aedes.calgarysolarcar.ca:3001"
: "http://localhost:3001";
14 changes: 7 additions & 7 deletions packages/shared/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ const IBatteryPackType = t.exact(

const IBatteryTemperatureType = t.exact(
t.type({
LowTemperature: t.number,
AverageTemperature: t.number,
InternalTemperature: t.number,
HighTemperature: t.number,
InternalTemperature: t.number,
LowTemperature: t.number,
}),
);

Expand Down Expand Up @@ -158,8 +158,8 @@ const IBatteryType = t.exact(

const IBatteryFaultsType = t.exact(
t.type({
Warnings: IBatteryFaultsWarningsType,
Errors: IBatteryFaultsErrorsType,
Warnings: IBatteryFaultsWarningsType,
}),
);

Expand Down Expand Up @@ -231,10 +231,10 @@ const IMotorErrorsType = t.exact(
CanCommsTimeoutError: t.boolean,
ControllerDataReadingTimeout: t.boolean,
DcOvervoltageError: t.boolean,
DcUndervoltageError: t.boolean,
ErrorInDclinkCommunication: t.boolean,
ErrorReadingEncoder: t.boolean,
ErrorReadingTempSensor: t.boolean,
DcUndervoltageError: t.boolean,
InvalidHallSensorSequence: t.boolean,
Inverter1FaultError: t.boolean,
Inverter1OvercurrentError: t.boolean,
Expand All @@ -259,17 +259,17 @@ const IMotorWarningsType = t.exact(
CanCommsTimeoutWarning: t.boolean,
DcOvervoltageWarning: t.boolean,
DcUndervoltageWarning: t.boolean,
Inverter1OverCurrentWarning: t.boolean,
Inverter1FaultWarning: t.boolean,
Inverter1OverCurrentWarning: t.boolean,
Inverter2FaultWarning: t.boolean,
Inverter2OverCurrentWarning: t.boolean,
Inverter3FaultWarning: t.boolean,
Inverter3OverCurrentWarning: t.boolean,
Inverter4FaultWarning: t.boolean,
Inverter4OverCurrentWarning: t.boolean,
Inverter5FaultWarning: t.boolean,
Inverter6FaultWarning: t.boolean,
Inverter5OverCurrentWarning: t.boolean,
Inverter6FaultWarning: t.boolean,
Inverter6OverCurrentWarning: t.boolean,
LostFramesOnCanBusWarning: t.boolean,
OverspeedWarning: t.boolean,
Expand Down Expand Up @@ -316,10 +316,10 @@ const IMotorDetailsType = t.exact(
InverterPeakCurrent: t.number,
MotorAboutToStall: t.boolean,
MotorErrors: IMotorErrorsType,
MotorWarnings: IMotorWarningsType,
MotorMode: t.boolean,
MotorStalled: t.boolean,
MotorTemperature: t.number,
MotorWarnings: IMotorWarningsType,
SettingsNotFound: t.boolean,
SoftwareEnable: t.boolean,
StartAtHighRpm: t.boolean,
Expand Down