Commit 2b2c3fc7 authored by Ryan Diehl's avatar Ryan Diehl

fix(cdn): makes CDN_CONFIG optional

this helps especially with testing
parent 7b0d4934
Pipeline #97138 passed with stages
in 6 minutes and 3 seconds
......@@ -251,3 +251,21 @@ describe('CdnService', () => {
});
});
});
describe('CdnService with no CDN_CONFIG', () => {
let service: CdnService;
beforeEach(() => {
TestBed.configureTestingModule({
providers: [CdnService]
});
service = TestBed.get(CdnService);
});
it('should create', () => {
expect(service).toBeDefined();
});
it('should use default baseUrl', () => {
expect(service.uri('test')).toBe('https://static.apps.psu.edu/test');
});
});
......@@ -15,7 +15,9 @@ import { CdnUri } from './cdn.model';
@Injectable({ providedIn: 'root' })
export class CdnService {
constructor(
@Inject(CDN_CONFIG) private config: CdnConfig,
@Optional()
@Inject(CDN_CONFIG)
private config: CdnConfig,
@Optional()
@Inject(CDN_RESOURCE_CONFIG)
private resourceConfig: CdnResourceConfig[],
......@@ -25,7 +27,10 @@ export class CdnService {
) {}
private get cdnUrl(): string {
let url = this.config.baseUrl || 'https://static.apps.psu.edu';
let url = 'https://static.apps.psu.edu';
if (this.config && this.config.baseUrl) {
url = this.config.baseUrl;
}
if (url && url.lastIndexOf('/') === url.length - 1) {
url = url.substr(0, url.length - 1);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment