mirror of
https://github.com/actualbudget/actual.git
synced 2026-04-30 03:23:51 -05:00
:electron: Removing node-fetch and updating root ca impl for more support (#3782)
* updating root ca impl to use node env variable for more support * release notes * removing node-fetch * clean up * error message * Update 3782.md
This commit is contained in:
@@ -15,6 +15,8 @@ import {
|
||||
UtilityProcess,
|
||||
OpenDialogSyncOptions,
|
||||
SaveDialogOptions,
|
||||
Env,
|
||||
ForkOptions,
|
||||
} from 'electron';
|
||||
import { copy, exists, remove } from 'fs-extra';
|
||||
import promiseRetry from 'promise-retry';
|
||||
@@ -56,11 +58,49 @@ if (isDev) {
|
||||
process.traceProcessWarnings = true;
|
||||
}
|
||||
|
||||
function createBackgroundProcess() {
|
||||
async function loadGlobalPrefs() {
|
||||
let state: { [key: string]: unknown } | undefined = undefined;
|
||||
try {
|
||||
state = JSON.parse(
|
||||
fs.readFileSync(
|
||||
path.join(process.env.ACTUAL_DATA_DIR!, 'global-store.json'),
|
||||
'utf8',
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
console.info('Could not load global state - using defaults'); // This could be the first time running the app - no global-store.json
|
||||
state = {};
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
async function createBackgroundProcess() {
|
||||
const globalPrefs = await loadGlobalPrefs(); // ensures we have the latest settings - even when restarting the server
|
||||
let envVariables: Env = {
|
||||
...process.env, // required
|
||||
};
|
||||
|
||||
if (globalPrefs?.['server-self-signed-cert']) {
|
||||
envVariables = {
|
||||
...envVariables,
|
||||
NODE_EXTRA_CA_CERTS: globalPrefs?.['server-self-signed-cert'], // add self signed cert to env - fetch can pick it up
|
||||
};
|
||||
}
|
||||
|
||||
let forkOptions: ForkOptions = {
|
||||
stdio: 'pipe',
|
||||
env: envVariables,
|
||||
};
|
||||
|
||||
if (isDev) {
|
||||
forkOptions = { ...forkOptions, execArgv: ['--inspect'] };
|
||||
}
|
||||
|
||||
serverProcess = utilityProcess.fork(
|
||||
__dirname + '/server.js',
|
||||
['--subprocess', app.getVersion()],
|
||||
isDev ? { execArgv: ['--inspect'], stdio: 'pipe' } : { stdio: 'pipe' },
|
||||
forkOptions,
|
||||
);
|
||||
|
||||
serverProcess.stdout?.on('data', (chunk: Buffer) => {
|
||||
|
||||
@@ -87,7 +87,6 @@
|
||||
"dependencies": {
|
||||
"better-sqlite3": "^9.6.0",
|
||||
"fs-extra": "^11.2.0",
|
||||
"node-fetch": "^2.7.0",
|
||||
"promise-retry": "^2.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
// @ts-strict-ignore
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
global.fetch = fetch;
|
||||
|
||||
const lazyLoadBackend = async (isDev: boolean) => {
|
||||
if (process.env.lootCoreScript === undefined) {
|
||||
throw new Error(
|
||||
'The environment variable `lootCoreScript` is not defined. Please define it to point to the server bundle.',
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const bundle = await import(process.env.lootCoreScript);
|
||||
bundle.initApp(isDev);
|
||||
} catch (error) {
|
||||
console.error('Failed to init the server bundle:', error);
|
||||
throw new Error(`Failed to init the server bundle: ${error.message}`);
|
||||
throw new Error(`Failed to init the server bundle: ${error}`);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user