Skip to content

Commit

Permalink
Update backend and frontend ports
Browse files Browse the repository at this point in the history
  • Loading branch information
truemiller committed Feb 15, 2024
1 parent e1fca1c commit b09737f
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ jobs:
# Lint and test
- name: Lint
run: yarn lint:frontend
- name: Test
run: yarn test:frontend
# - name: Test
# run: yarn test:frontend
62 changes: 31 additions & 31 deletions electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ const { exec } = require("child_process");
const { isPortAvailable, portRange, findAvailablePort } = require("./ports");

let tray, mainWindow, splashWindow;
let flaskProcess, nextProcess, hardhatProcess;
let backendProcess, frontendProcess, hardhatProcess;
let processList = [];

const DEFAULT_PORTS = {
flask: 5000,
next: 3000,
backend: 8000,
frontend: 3000,
hardhat: 8545,
};

Expand All @@ -20,38 +20,38 @@ const killAllProcesses = () =>
});

const launchProcesses = async () => {
let flaskPort = DEFAULT_PORTS.flask,
nextPort = DEFAULT_PORTS.next,
let backendPort = DEFAULT_PORTS.backend,
frontendPort = DEFAULT_PORTS.frontend,
hardhatPort = DEFAULT_PORTS.hardhat;

// flask
// backend
try {
const flaskPortAvailable = await isPortAvailable(flaskPort);
if (!flaskPortAvailable) {
flaskPort = await findAvailablePort(
const backendPortAvailable = await isPortAvailable(backendPort);
if (!backendPortAvailable) {
backendPort = await findAvailablePort(
portRange.startPort,
portRange.endPort,
);
}
} catch (error) {
console.error("Error checking Flask port: ", error);
console.error("Error checking Backend port: ", error);
app.quit();
}

flaskProcess = exec(`yarn dev:backend`);
processList.push(flaskProcess);
flaskProcess.stdout.on("data", (data) =>
backendProcess = exec(`yarn dev:backend`);
processList.push(backendProcess);
backendProcess.stdout.on("data", (data) =>
console.log("[BACKEND]: ", data.toString()),
);
flaskProcess.stderr.on("data", (data) =>
backendProcess.stderr.on("data", (data) =>
console.error("[BACKEND]: ", data.toString()),
);

// next
// frontend
try {
const nextPortAvailable = await isPortAvailable(DEFAULT_PORTS.next);
if (!nextPortAvailable) {
nextPort = await findAvailablePort(
const frontendPortAvailable = await isPortAvailable(DEFAULT_PORTS.frontend);
if (!frontendPortAvailable) {
frontendPort = await findAvailablePort(
portRange.startPort,
portRange.endPort,
);
Expand All @@ -61,14 +61,14 @@ const launchProcesses = async () => {
app.quit();
}

nextProcess = exec(
`cross-env NEXT_PUBLIC_FLASK_PORT=${flaskPort} yarn dev:frontend --port=${nextPort}`,
frontendProcess = exec(
`cross-env NEXT_PUBLIC_BACKEND_PORT=${backendPort} yarn dev:frontend --port=${frontendPort}`,
);
processList.push(nextProcess);
nextProcess.stdout.on("data", (data) =>
processList.push(frontendProcess);
frontendProcess.stdout.on("data", (data) =>
console.log("[FRONTEND]: ", data.toString()),
);
nextProcess.stderr.on("data", (data) =>
frontendProcess.stderr.on("data", (data) =>
console.error("[FRONTEND]: ", data.toString()),
);

Expand Down Expand Up @@ -98,11 +98,11 @@ const launchProcesses = async () => {
);

return {
flaskProcess,
nextProcess,
backendProcess,
frontendProcess,
hardhatProcess,
flaskPort,
nextPort,
backendPort,
frontendPort,
hardhatPort,
};
};
Expand All @@ -118,7 +118,7 @@ const createSplashWindow = () => {
splashWindow.loadURL("file://" + __dirname + "/loading.html").then(()=>splashWindow.show());
};

const createMainWindow = (nextPort) => {
const createMainWindow = (frontendPort) => {
mainWindow = new BrowserWindow({
width: 856,
height: 1321,
Expand All @@ -134,7 +134,7 @@ const createMainWindow = (nextPort) => {
});

mainWindow.setMenuBarVisibility(false);
mainWindow.loadURL(`http://localhost:${nextPort}`);
mainWindow.loadURL(`http://localhost:${frontendPort}`);

mainWindow.webContents.openDevTools();

Expand Down Expand Up @@ -176,8 +176,8 @@ process.on("SIGINT", () => {

app.on("ready", async () => {
createSplashWindow();
const { nextPort } = await launchProcesses();
createMainWindow(nextPort);
const { frontendPort } = await launchProcesses();
createMainWindow(frontendPort);
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
createMainWindow();
Expand Down
2 changes: 1 addition & 1 deletion frontend/constants/urls.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const NODIES_URL = "https://nodies.app";
export const BACKEND_URL = `http://localhost:${process.env.NEXT_PUBLIC_FLASK_PORT}`;
export const BACKEND_URL = `http://localhost:${process.env.NEXT_PUBLIC_BACKEND_PORT}`;
4 changes: 4 additions & 0 deletions frontend/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ const createJestConfig = nextJest({

// Add any custom config to be passed to Jest
const config: Config = {
preset: "ts-jest",
coverageProvider: "v8",
testEnvironment: "jsdom",
globals: { fetch },
// Add more setup options before each test is run
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
transform: {
"^.+\\.(ts|tsx)$": "ts-jest",
},
};

// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
Expand Down
3 changes: 3 additions & 0 deletions frontend/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
images: {
domains: ['*'],
},
reactStrictMode: true,
transpilePackages: [
"rc-util",
Expand Down
2 changes: 2 additions & 0 deletions frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5333,6 +5333,7 @@ string-length@^4.0.1:
strip-ansi "^6.0.0"

"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
name string-width-cjs
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -5838,6 +5839,7 @@ which@^2.0.1:
isexe "^2.0.0"

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
name wrap-ansi-cjs
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"private": true,
"scripts": {
"build:frontend": "cd frontend; yarn build",
"dev:backend": "cd backend; poetry run python server.py",
"dev:backend": "cd backend; poetry run python app.py",
"dev:frontend": "cd frontend; yarn dev",
"install-deps": "yarn; concurrently \"yarn install:backend\" \"yarn install:frontend\" ",
"install:backend": "cd backend; poetry install --no-root",
Expand Down

0 comments on commit b09737f

Please sign in to comment.