Skip to content

Commit

Permalink
fix config loading
Browse files Browse the repository at this point in the history
  • Loading branch information
nleush committed Nov 12, 2021
1 parent 5c24bf3 commit d81041c
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 16 deletions.
2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { cacheMiddleware, NotFound } from './utils.js';
import CONFIG from './config.loader.js';
global.CONFIG = CONFIG;

console.log("");
console.log("Starting Iframely...");
Expand Down
3 changes: 3 additions & 0 deletions config.loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var globalConfig = await import(process.cwd() + '/config.js');
globalConfig = globalConfig && globalConfig.default;
export default globalConfig;
2 changes: 1 addition & 1 deletion lib/cache-engines/memcached.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import log from '../../logging.js';
import * as crypto from 'crypto';
import Memcached from 'memcached';
import CONFIG from '../../config.js';
import CONFIG from '../../config.loader.js';

var memcached = new Memcached(CONFIG.MEMCACHED_OPTIONS && CONFIG.MEMCACHED_OPTIONS.locations, CONFIG.MEMCACHED_OPTIONS && CONFIG.MEMCACHED_OPTIONS.options);

Expand Down
2 changes: 1 addition & 1 deletion lib/cache-engines/node-cache.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import NodeCache from "node-cache";
import CONFIG from '../../config.js';
import CONFIG from '../../config.loader.js';

var nodeCache = new NodeCache({
stdTTL: CONFIG.CACHE_TTL,
Expand Down
2 changes: 1 addition & 1 deletion lib/cache-engines/redis.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import log from '../../logging.js';
import CONFIG from '../../config.js';
import CONFIG from '../../config.loader.js';

var client;

Expand Down
2 changes: 1 addition & 1 deletion lib/cache.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as _ from 'underscore';
import CONFIG from '../config.js';
import CONFIG from '../config.loader.js';

var DEFAULT_CACHE = "node-cache";

Expand Down
2 changes: 1 addition & 1 deletion lib/html-utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import cheerio from 'cheerio';

import * as _ from 'underscore';
import CONFIG from '../config.js';
import CONFIG from '../config.loader.js';

var defaultPaddingBottom = 100 / CONFIG.DEFAULT_ASPECT_RATIO;

Expand Down
4 changes: 4 additions & 0 deletions lib/loader/pluginLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
var JSLINT = node_jslint.load('latest');
import * as utils from './utils.js';

import CONFIG from '../../config.loader.js';
// Global CONFIG used by plugins loaded during module import.
global.CONFIG = CONFIG;

var PLUGIN_METHODS = utils.PLUGIN_METHODS,
PLUGINS_FIELDS = utils.PLUGIN_FIELDS,
PLUGIN_FIELDS_TYPE_DICT = utils.PLUGIN_FIELDS_TYPE_DICT,
Expand Down
6 changes: 1 addition & 5 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ import { cache } from './cache.js';
import * as htmlUtils from './html-utils.js';
import log from '../logging.js';

if (!global.CONFIG) {
// TODO: review
var config = await import('../config.js');
global.CONFIG = config.default;
}
import CONFIG from '../config.loader.js';

function prepareEncodedUri(request_options, attr) {
var url = request_options[attr];
Expand Down
2 changes: 2 additions & 0 deletions lib/whitelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import { fileURLToPath } from 'url';
import { dirname } from 'path';

import CONFIG from '../config.loader.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

Expand Down
3 changes: 1 addition & 2 deletions modules/tests-ui/models.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import moment from 'moment';
import mongoose from 'mongoose';
import config from '../../config.js';
global.CONFIG = config;
import CONFIG from '../../config.loader.js';

mongoose.set('useUnifiedTopology', true);
mongoose.set('useCreateIndex', true);
Expand Down
2 changes: 1 addition & 1 deletion modules/tests-ui/tester.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import config from '../../config.js';
import CONFIG from '../../config.loader.js';
global.CONFIG = config;

if (!CONFIG.tests) {
Expand Down
3 changes: 0 additions & 3 deletions utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import config from './config.js';
global.CONFIG = config;

import * as async from 'async';
import { cache } from './lib/cache.js';
import * as ejs from 'ejs';
Expand Down

0 comments on commit d81041c

Please sign in to comment.