|
6 | 6 | import { randomBytes } from 'crypto';
|
7 | 7 | import { readFileSync } from 'fs';
|
8 | 8 | import { ServerResponse } from 'http';
|
9 |
| -import { join } from 'path'; |
| 9 | +import * as path from 'path'; |
10 | 10 | import { MatchResult } from 'path-to-regexp';
|
11 | 11 | import { UriComponents } from 'vs/base/common/uri';
|
12 | 12 | import { ParsedRequest } from 'vs/server/services/net/abstractIncomingRequestService';
|
13 | 13 | import * as Handlebars from 'handlebars';
|
14 | 14 | import { IWorkbenchConfigurationSerialized } from 'vs/platform/workspaces/common/workbench';
|
15 | 15 |
|
16 |
| -export const APP_ROOT = join(__dirname, '..', '..', '..', '..', '..', '..'); |
17 |
| -export const WORKBENCH_PATH = join(APP_ROOT, 'out', 'vs', 'code', 'browser', 'workbench'); |
| 16 | +export const APP_ROOT = path.join(__dirname, '..', '..', '..', '..', '..', '..'); |
| 17 | +export const WORKBENCH_PATH = path.join(APP_ROOT, 'out', 'vs', 'code', 'browser', 'workbench'); |
18 | 18 | export const SERVICE_WORKER_FILE_NAME = 'service-worker.js';
|
19 | 19 |
|
20 | 20 | export const AssetPaths = {
|
21 | 21 | StaticBase: '/static',
|
22 |
| - Webview: join(APP_ROOT, 'out', 'vs', 'workbench', 'contrib', 'webview', 'browser', 'pre'), |
23 |
| - Favicon: join(APP_ROOT, 'resources', 'web', 'favicon.ico'), |
24 |
| - ServiceWorker: join(APP_ROOT, 'out', 'vs', 'code', 'browser', 'workbench', SERVICE_WORKER_FILE_NAME), |
| 22 | + ProxyUri: '/proxy/{port}', |
| 23 | + Webview: path.join(APP_ROOT, 'out', 'vs', 'workbench', 'contrib', 'webview', 'browser', 'pre'), |
| 24 | + Favicon: path.join(APP_ROOT, 'resources', 'web', 'favicon.ico'), |
| 25 | + ServiceWorker: path.join(APP_ROOT, 'out', 'vs', 'code', 'browser', 'workbench', SERVICE_WORKER_FILE_NAME), |
25 | 26 | };
|
26 | 27 |
|
27 | 28 | /** Matching the given keys in `PollingURLCallbackProvider.QUERY_KEYS` */
|
@@ -142,3 +143,18 @@ export interface ClientTheme {
|
142 | 143 | backgroundColor: string;
|
143 | 144 | foregroundColor: string;
|
144 | 145 | }
|
| 146 | + |
| 147 | +/** |
| 148 | + * Returns the relative path prefix for a given URL path. |
| 149 | + * @remark This is especially useful when creating URLs which have to remain |
| 150 | + * relative to an initial request. |
| 151 | + * |
| 152 | + * @example |
| 153 | + * ```ts |
| 154 | + * const url = new URL('https://www.example.com/foo/bar/baz.js') |
| 155 | + * getPathPrefix(url.pathname) // '/foo/bar/' |
| 156 | + * ``` |
| 157 | + */ |
| 158 | +export function getPathPrefix(pathname: string) { |
| 159 | + return path.join(path.dirname(pathname), '/'); |
| 160 | +} |
0 commit comments