Skip to content

Commit

Permalink
Merge pull request #136 from valory-xyz/josh/quick-backend-port-fix
Browse files Browse the repository at this point in the history
fix: quick fix for backend port during production build
  • Loading branch information
truemiller authored May 27, 2024
2 parents 83ac1a3 + d62645a commit b924fda
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
33 changes: 22 additions & 11 deletions electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,16 @@ async function launchDaemon() {

// Free up backend port if already occupied
try {
await fetch(`http://localhost:${appConfig.ports.prod.operate}/api`)
console.log("Killing backend server!")
let endpoint = fs.readFileSync(`${OperateDirectory}/operate.kill`)
await fetch(`http://localhost:${appConfig.ports.prod.operate}/api`);
console.log('Killing backend server!');
let endpoint = fs
.readFileSync(`${OperateDirectory}/operate.kill`)
.toString()
.trimLeft()
.trimRight()
await fetch(`http://localhost:${appConfig.ports.prod.operate}/${endpoint}`)
.trimRight();
await fetch(`http://localhost:${appConfig.ports.prod.operate}/${endpoint}`);
} catch (err) {
console.log("Backend not running!")
console.log('Backend not running!');
}

const check = new Promise(function (resolve, _reject) {
Expand All @@ -295,9 +296,13 @@ async function launchDaemon() {
{ env: Env },
);
operateDaemonPid = operateDaemon.pid;
fs.appendFileSync(`${OperateDirectory}/operate.pip`, `${operateDaemon.pid}`, {
encoding: 'utf-8',
});
fs.appendFileSync(
`${OperateDirectory}/operate.pip`,
`${operateDaemon.pid}`,
{
encoding: 'utf-8',
},
);

operateDaemon.stderr.on('data', (data) => {
if (data.toString().includes('Uvicorn running on')) {
Expand Down Expand Up @@ -355,7 +360,10 @@ async function launchNextApp() {
process.env.NODE_ENV === 'production'
? process.env.FORK_URL
: process.env.DEV_RPC,
NEXT_PUBLIC_BACKEND_PORT: appConfig.ports.prod.operate
NEXT_PUBLIC_BACKEND_PORT:
process.env.NODE_ENV === 'production'
? appConfig.ports.prod.operate
: appConfig.ports.dev.operate,
},
});
await nextApp.prepare();
Expand All @@ -379,7 +387,10 @@ async function launchNextAppDev() {
'yarn',
['dev:frontend', '--port', appConfig.ports.dev.next],
{
env: { ...process.env, NEXT_PUBLIC_BACKEND_PORT: appConfig.ports.dev.operate },
env: {
...process.env,
NEXT_PUBLIC_BACKEND_PORT: appConfig.ports.dev.operate,
},
},
);
nextAppProcessPid = nextAppProcess.pid;
Expand Down
2 changes: 1 addition & 1 deletion frontend/constants/urls.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const BACKEND_URL: string = `http://localhost:${process.env.NEXT_PUBLIC_BACKEND_PORT || 8000}/api`;
export const BACKEND_URL: string = `http://localhost:${process.env.NODE_ENV === 'production' ? 8765 : 8000}/api`;
export const COW_SWAP_GNOSIS_XDAI_OLAS_URL: string =
'https://swap.cow.fi/#/100/swap/WXDAI/OLAS';
export const SUPPORT_URL =
Expand Down

0 comments on commit b924fda

Please sign in to comment.