Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HTTP] Add support for configuring a CDN (part I) #169408

Merged
merged 21 commits into from
Oct 21, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added static assets test and minor refactor
jloleysens committed Oct 19, 2023
commit 02a2781f952f1b9fa7538ba808c58622e955507b
8 changes: 4 additions & 4 deletions packages/core/http/core-http-server-internal/src/cdn.ts
Original file line number Diff line number Diff line change
@@ -15,9 +15,9 @@ export interface Input {

export class CdnConfig {
private url: undefined | URL;
constructor(private readonly input: Input) {
if (this.input.url) {
this.url = new URL(this.input.url); // This will throw for invalid URLs
constructor(url?: string) {
if (url) {
this.url = new URL(url); // This will throw for invalid URLs
}
}

@@ -47,6 +47,6 @@ export class CdnConfig {
}

public static from(input: Input = {}) {
return new CdnConfig(input);
return new CdnConfig(input.url);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { StaticAssets } from './static_assets';
import { BasePath } from './base_path_service';
import { CdnConfig } from './cdn';
import { mockRouter } from '@kbn/core-http-router-server-mocks';

describe('StaticAssets', () => {
let basePath: BasePath;
let cdnConfig: CdnConfig;
let staticAssets: StaticAssets;
beforeEach(() => {
basePath = new BasePath('/test');
cdnConfig = CdnConfig.from();
staticAssets = new StaticAssets(basePath, cdnConfig);
});
it('provides fallsback to server base path', () => {
expect(staticAssets.getHrefBase()).toEqual('/test');
});

it('can be scoped with Kibana request', () => {
const req = mockRouter.createKibanaRequest();
basePath.set(req, '/my-space');
expect(staticAssets.getHrefBase(req)).toEqual('/test/my-space');
});

it('provides the correct HREF given a CDN is configured', () => {
cdnConfig = CdnConfig.from({ url: 'https://cdn.example.com/test' });
staticAssets = new StaticAssets(basePath, cdnConfig);
expect(staticAssets.getHrefBase()).toEqual('https://cdn.example.com/test');
});
});