diff --git a/src/server/app.ts b/src/server/app.ts index 255fb94..a889d79 100644 --- a/src/server/app.ts +++ b/src/server/app.ts @@ -26,11 +26,13 @@ export default async function createApp(config: IConfig): Promise { allowMethods: ['GET'], credentials: true, origin: (ctx: Koa.Context) => { + const origin = ctx.get('Origin'); if ( - /^https:\/\/[^.]+\.vscode-cdn\.net$/.test(ctx.get('Origin')) || // needed for the webviewContent - /^https:\/\/[^.]+\.vscode-webview\.net$/.test(ctx.get('Origin')) + /^https:\/\/[^.]+\.vscode-cdn\.net$/.test(origin) || // needed for the webviewContent + /^https:\/\/[^.]+\.vscode-webview\.net$/.test(origin) || + new RegExp(`^${ctx.protocol}://[^.]+\\.${ctx.host}$`).test(origin) // match subdomains of localhost ) { - return ctx.get('Origin'); + return origin; } return undefined as any; @@ -38,7 +40,7 @@ export default async function createApp(config: IConfig): Promise { }) ); - if (config.build.type !== 'sources') { + if (config.build.type !== 'sources' && config.build.type !== 'static') { // CSP: frame-ancestors app.use((ctx, next) => { ctx.set('Content-Security-Policy', `frame-ancestors 'none'`); diff --git a/src/server/workbench.ts b/src/server/workbench.ts index e1918ed..1ebc92e 100644 --- a/src/server/workbench.ts +++ b/src/server/workbench.ts @@ -137,7 +137,11 @@ export default function (config: IConfig): Router.Middleware { const productOverrides = await getProductOverrides(config.build.location); ctx.state.workbench = new Workbench(`${ctx.protocol}://${ctx.host}/static/sources`, true, config.esm, builtInExtensions, productOverrides); } else if (config.build.type === 'static') { - ctx.state.workbench = new Workbench(`${ctx.protocol}://${ctx.host}/static/build`, false, config.esm); + const baseUrl = `${ctx.protocol}://${ctx.host}/static/build`; + const baseUrlTemplate = `${ctx.protocol}://{{uuid}}.${ctx.host}/static/build`; + ctx.state.workbench = new Workbench(baseUrl, false, config.esm, [], { + webEndpointUrlTemplate: baseUrlTemplate, + }); } else if (config.build.type === 'cdn') { ctx.state.workbench = new Workbench(config.build.uri, false, config.esm); }