diff --git a/app/gui2/config.yaml b/app/gui2/config.yaml deleted file mode 100644 index 927581cc1e08..000000000000 --- a/app/gui2/config.yaml +++ /dev/null @@ -1,30 +0,0 @@ -# The name of an object created in the global window scope. This object will contain functions -# to control the IDE, like the `main` function, and also the configuration object. -windowAppScopeName: 'enso' - -# The configuration object nested inside of the `windowAppScopeName` object containing all -# startup configuration options. See usages of this variable to learn more about available -# options. -windowAppScopeConfigName: 'config' - -# The configuration object nested inside of the `windowAppScopeName` object containing theming -# utilities and allowing for runtime theme modification. -windowAppScopeThemeName: 'theme' - -# The URL to the JSON-RPC endpoint to the Project Manager. -# This MUST be kept in sync with the corresponding value in `app/gui/src/constants.rs`. -projectManagerEndpoint: 'ws://127.0.0.1:30535' - -# The URL to the base path of the HTTP endpoints of the Project Manager. -projectManagerHttpEndpoint: 'http://127.0.0.1:30535' - -# TODO [ao] add description here. -minimumSupportedVersion": '2.0.0-alpha.6' - -# The minimum engine version supported by the application. The projects opened with the older versions -# will have the "Unsupported engine version" message displayed. -engineVersionSupported: '2023.1.1' - -# The minimum language edition supported by the application. It will be displayed as edition user -# should put in their package.yaml file to have project compatible with the IDE. -languageEditionSupported: '2023.1.1' diff --git a/app/ide-desktop/eslint.config.js b/app/ide-desktop/eslint.config.js index 3206111f579a..58a9d51d4e49 100644 --- a/app/ide-desktop/eslint.config.js +++ b/app/ide-desktop/eslint.config.js @@ -30,7 +30,7 @@ const NAME = 'enso' * `yargs` is a modules we explicitly want the default imports of. * `node:process` is here because `process.on` does not exist on the namespace import. */ const DEFAULT_IMPORT_ONLY_MODULES = - '@vitejs\\u002Fplugin-react|node:process|chalk|string-length|yargs|yargs\\u002Fyargs|sharp|to-ico|connect|morgan|serve-static|tiny-invariant|clsx|create-servers|electron-is-dev|fast-glob|esbuild-plugin-.+|opener|tailwindcss.*|enso-assets.*|@modyfi\\u002Fvite-plugin-yaml|is-network-error|validator.+' + '@vitejs\\u002Fplugin-react|node:process|chalk|string-length|yargs|yargs\\u002Fyargs|sharp|to-ico|connect|morgan|serve-static|tiny-invariant|clsx|create-servers|electron-is-dev|fast-glob|esbuild-plugin-.+|opener|tailwindcss.*|enso-assets.*|@modyfi\\u002Fvite-plugin-yaml|is-network-error|validator.+|.*[.]json$' const OUR_MODULES = 'enso-.*' const RELATIVE_MODULES = 'bin\\u002Fproject-manager|bin\\u002Fserver|config\\u002Fparser|authentication|config|debug|detect|file-associations|index|ipc|log|naming|paths|preload|project-management|security|url-associations|#\\u002F.*' diff --git a/app/ide-desktop/lib/client/src/bin/server.ts b/app/ide-desktop/lib/client/src/bin/server.ts index 80b16f1e4511..7c2b0a8feeb7 100644 --- a/app/ide-desktop/lib/client/src/bin/server.ts +++ b/app/ide-desktop/lib/client/src/bin/server.ts @@ -13,14 +13,12 @@ import type * as vite from 'vite' import createServer from 'create-servers' import * as common from 'enso-common' +import GLOBAL_CONFIG from 'enso-common/src/config.json' assert { type: 'json' } import * as contentConfig from 'enso-content-config' import * as ydocServer from 'enso-gui2/ydoc-server' import * as paths from '../paths' -// prettier-ignore -import GLOBAL_CONFIG from '../../../../../gui2/config.yaml' assert { type: 'yaml' } - const logger = contentConfig.logger // ================= diff --git a/app/ide-desktop/lib/client/src/index.ts b/app/ide-desktop/lib/client/src/index.ts index d55146c4b99b..76cc92990a74 100644 --- a/app/ide-desktop/lib/client/src/index.ts +++ b/app/ide-desktop/lib/client/src/index.ts @@ -16,6 +16,7 @@ import * as portfinder from 'portfinder' import * as common from 'enso-common' import * as buildUtils from 'enso-common/src/buildUtils' +import GLOBAL_CONFIG from 'enso-common/src/config.json' assert { type: 'json' } import * as contentConfig from 'enso-content-config' import * as authentication from 'authentication' @@ -34,9 +35,6 @@ import * as security from 'security' import * as server from 'bin/server' import * as urlAssociations from 'url-associations' -// prettier-ignore -import GLOBAL_CONFIG from '../../../../gui2/config.yaml' assert { type: 'yaml' } - const logger = contentConfig.logger if (process.env.ELECTRON_DEV_MODE === 'true' && process.env.NODE_MODULES_PATH != null) { diff --git a/app/ide-desktop/lib/common/package.json b/app/ide-desktop/lib/common/package.json index ccd5db0e9aef..c4de52675d11 100644 --- a/app/ide-desktop/lib/common/package.json +++ b/app/ide-desktop/lib/common/package.json @@ -5,6 +5,7 @@ "main": "./src/index.js", "exports": { ".": "./src/index.js", + "./src/config.json": "./src/config.json", "./src/appConfig": "./src/appConfig.js", "./src/buildUtils": "./src/buildUtils.js", "./src/detect": "./src/detect.ts", diff --git a/app/ide-desktop/lib/common/src/config.json b/app/ide-desktop/lib/common/src/config.json new file mode 100644 index 000000000000..da583ac08d51 --- /dev/null +++ b/app/ide-desktop/lib/common/src/config.json @@ -0,0 +1,4 @@ +{ + "projectManagerEndpoint": "ws://127.0.0.1:30535", + "projectManagerHttpEndpoint": "http://127.0.0.1:30535" +} diff --git a/app/ide-desktop/lib/project-manager-shim/src/projectManagerShimMiddleware.ts b/app/ide-desktop/lib/project-manager-shim/src/projectManagerShimMiddleware.ts index a847daedc2c9..b34e5600d655 100644 --- a/app/ide-desktop/lib/project-manager-shim/src/projectManagerShimMiddleware.ts +++ b/app/ide-desktop/lib/project-manager-shim/src/projectManagerShimMiddleware.ts @@ -2,7 +2,7 @@ import * as fs from 'node:fs/promises' import * as fsSync from 'node:fs' -import type * as http from 'node:http' +import * as http from 'node:http' import * as os from 'node:os' import * as path from 'node:path' @@ -10,6 +10,8 @@ import * as tar from 'tar' import * as yaml from 'yaml' import * as common from 'enso-common' +import GLOBAL_CONFIG from '../../common/src/config.json' assert { type: 'json' } + import * as projectManagement from './projectManagement' // ================= @@ -97,7 +99,37 @@ export default function projectManagerShimMiddleware( ) { const requestUrl = request.url const requestPath = requestUrl?.split('?')[0]?.split('#')[0] - if (request.method === 'POST') { + if (requestUrl != null && requestUrl.startsWith('/api/project-manager/')) { + const actualUrl = new URL( + requestUrl.replace(/^\/api\/project-manager/, GLOBAL_CONFIG.projectManagerHttpEndpoint) + ) + request.pipe( + http.request( + // `...actualUrl` does NOT work because `URL` properties are not enumerable. + { + headers: request.headers, + host: actualUrl.host, + hostname: actualUrl.hostname, + method: request.method, + path: actualUrl.pathname, + port: actualUrl.port, + protocol: actualUrl.protocol, + }, + actualResponse => { + response.writeHead( + // This is SAFE. The documentation says: + // Only valid for response obtained from ClientRequest. + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + actualResponse.statusCode!, + actualResponse.statusMessage, + actualResponse.headers + ) + actualResponse.pipe(response, { end: true }) + } + ), + { end: true } + ) + } else if (request.method === 'POST') { switch (requestPath) { case '/api/upload-file': { const url = new URL(`https://example.com/${requestUrl}`) diff --git a/app/ide-desktop/lib/project-manager-shim/tsconfig.json b/app/ide-desktop/lib/project-manager-shim/tsconfig.json index 0a921bf939ad..c2dcc3ed7b17 100644 --- a/app/ide-desktop/lib/project-manager-shim/tsconfig.json +++ b/app/ide-desktop/lib/project-manager-shim/tsconfig.json @@ -5,5 +5,5 @@ "checkJs": false, "skipLibCheck": false }, - "include": ["./src/"] + "include": ["./src/", "../common/src/config.json"] } diff --git a/app/ide-desktop/lib/types/modules.d.ts b/app/ide-desktop/lib/types/modules.d.ts index b32b3c558c58..e4ea8bbef2fe 100644 --- a/app/ide-desktop/lib/types/modules.d.ts +++ b/app/ide-desktop/lib/types/modules.d.ts @@ -20,23 +20,6 @@ declare module '*/build.json' { export default BUILD_INFO } -declare module '*/gui2/config.yaml' { - /** Content of the GUI config file. */ - interface Config { - readonly windowAppScopeName: string - readonly windowAppScopeConfigName: string - readonly windowAppScopeThemeName: string - readonly projectManagerEndpoint: string - readonly projectManagerHttpEndpoint: string - readonly minimumSupportedVersion: string - readonly engineVersionSupported: string - readonly languageEditionSupported: string - } - - const DATA: Config - export default DATA -} - declare module '@eslint/js' { /** A set of configurations. */ export interface Config {