2021-11-11 15:48:36 +03:00
|
|
|
const config = require('../../../shared/config');
|
2021-11-18 14:42:56 +03:00
|
|
|
const LocalFileCache = require('./LocalFileCache');
|
2020-04-29 18:44:27 +03:00
|
|
|
const UrlService = require('./UrlService');
|
2021-11-11 15:48:36 +03:00
|
|
|
|
|
|
|
// NOTE: instead of a path we could give UrlService a "data-resolver" of some sort
|
|
|
|
// so it doesn't have to contain the logic to read data at all. This would be
|
|
|
|
// a possible improvement in the future
|
2021-11-18 15:01:57 +03:00
|
|
|
let writeDisabled = false;
|
2021-11-18 14:42:56 +03:00
|
|
|
let storagePath = config.getContentPath('data');
|
2021-11-17 19:05:17 +03:00
|
|
|
|
|
|
|
// TODO: remove this hack in favor of loading from the content path when it's possible to do so
|
|
|
|
// by mocking content folders in pre-boot phase
|
|
|
|
if (process.env.NODE_ENV.match(/^testing/)){
|
2021-11-18 14:42:56 +03:00
|
|
|
storagePath = config.get('paths').urlCache;
|
2021-11-18 15:01:57 +03:00
|
|
|
|
|
|
|
// NOTE: prevents test suites from overwriting cache fixtures.
|
|
|
|
// A better solution would be injecting a different implementation of the
|
|
|
|
// cache based on the environment, this approach should do the trick for now
|
|
|
|
writeDisabled = true;
|
2021-11-17 19:05:17 +03:00
|
|
|
}
|
|
|
|
|
2021-11-18 15:01:57 +03:00
|
|
|
const cache = new LocalFileCache({storagePath, writeDisabled});
|
2021-11-18 14:42:56 +03:00
|
|
|
const urlService = new UrlService({cache});
|
2017-12-11 18:56:04 +03:00
|
|
|
|
|
|
|
// Singleton
|
|
|
|
module.exports = urlService;
|