Skip to content

Commit c0df495

Browse files
rahul-rocketgreptile-apps[bot]cubic-dev-ai[bot]
authored
fix(ai): applied AI suggestions from stage apps branch (#9597)
* Apply suggestion from @coderabbitai[bot] * Update apps/desktop/src/index.ts Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * Update .scripts/electron-desktop-environment/concrete-environment-content/desktop-environment-content.ts Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> --------- Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
1 parent 99c86c9 commit c0df495

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

.scripts/electron-desktop-environment/concrete-environment-content/desktop-api-server-environment-content.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { IContentGenerator } from '../interfaces/i-content-generator';
22
import { IDesktopEnvironment } from '../interfaces/i-desktop-environment';
3+
import { escapeForSingleQuote } from '../utils/escape-string';
34

45
export class DesktopApiServerEnvironmentContent implements IContentGenerator {
56
/**
@@ -30,8 +31,8 @@ export class DesktopApiServerEnvironmentContent implements IContentGenerator {
3031
IS_DESKTOP: ${false},
3132
IS_SERVER: ${true},
3233
IS_SERVER_API: ${true},
33-
JWT_SECRET: '${variable.DESKTOP_JWT_SECRET || ''}',
34-
JWT_REFRESH_TOKEN_SECRET: '${variable.DESKTOP_JWT_REFRESH_TOKEN_SECRET || ''}'
34+
JWT_SECRET: '${escapeForSingleQuote(variable.DESKTOP_JWT_SECRET || '')}',
35+
JWT_REFRESH_TOKEN_SECRET: '${escapeForSingleQuote(variable.DESKTOP_JWT_REFRESH_TOKEN_SECRET || '')}'
3536
`;
3637
}
3738
}

.scripts/electron-desktop-environment/concrete-environment-content/desktop-server-environment-content.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { IContentGenerator } from '../interfaces/i-content-generator';
22
import { IDesktopEnvironment } from '../interfaces/i-desktop-environment';
3+
import { escapeForSingleQuote } from '../utils/escape-string';
34

45
export class DesktopServerEnvironmentContent implements IContentGenerator {
56
/**
@@ -30,8 +31,8 @@ export class DesktopServerEnvironmentContent implements IContentGenerator {
3031
IS_DESKTOP: ${false},
3132
IS_SERVER: ${true},
3233
IS_SERVER_API: ${false},
33-
JWT_SECRET: '${variable.DESKTOP_JWT_SECRET || ''}',
34-
JWT_REFRESH_TOKEN_SECRET: '${variable.DESKTOP_JWT_REFRESH_TOKEN_SECRET || ''}'
34+
JWT_SECRET: '${escapeForSingleQuote(variable.DESKTOP_JWT_SECRET || '')}',
35+
JWT_REFRESH_TOKEN_SECRET: '${escapeForSingleQuote(variable.DESKTOP_JWT_REFRESH_TOKEN_SECRET || '')}'
3536
`;
3637
}
3738
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Escapes a string so it can be safely embedded inside a single-quoted
3+
* JavaScript string literal in generated source code.
4+
*
5+
* Handles backslashes, single quotes, and newline characters that would
6+
* otherwise break or alter the emitted string.
7+
*
8+
* @param value - The raw string to escape.
9+
* @returns The escaped string, safe for single-quote interpolation.
10+
*/
11+
export function escapeForSingleQuote(value: string): string {
12+
return value.replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/\n/g, '\\n').replace(/\r/g, '\\r');
13+
}

apps/desktop/src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,12 @@ async function startServer(setupConfig: DesktopSetupConfig, restart = false) {
347347
process.env.API_PORT = setupConfig.port ? String(setupConfig.port) : String(environment.API_DEFAULT_PORT);
348348
process.env.API_HOST = '0.0.0.0';
349349
process.env.API_BASE_URL = `http://127.0.0.1:${setupConfig.port || environment.API_DEFAULT_PORT}`;
350-
process.env.JWT_SECRET = setupConfig.secret?.jwt;
351-
process.env.JWT_REFRESH_TOKEN_SECRET = setupConfig.secret?.refresh_token;
350+
351+
if (!setupConfig.secret || !setupConfig.secret.jwt || !setupConfig.secret.refresh_token) {
352+
throw new AppError('MAINSTRSERVER', new Error('JWT secrets are required for local server startup'));
353+
}
354+
process.env.JWT_SECRET = setupConfig.secret.jwt;
355+
process.env.JWT_REFRESH_TOKEN_SECRET = setupConfig.secret.refresh_token;
352356

353357
console.log('Setting additional environment variables...', process.env.API_PORT);
354358
console.log('Setting additional environment variables...', process.env.API_HOST);

0 commit comments

Comments
 (0)