Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 5 additions & 5 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ class Application extends EventEmitter {
this.cache = new Map();
this.path = APP_PATH;
this.cert = { key: TLS_KEY, cert: TLS_CERT };
this.config = new Config(CFG_PATH);
this.logger = new Logger(LOG_PATH, worker.threadId);
this.sandbox = null;
this.db = null;
this.server = null;
this.config.on('loaded', () => {
const { sections } = this.config;
this.cacheDirectory(STATIC_PATH);
this.cacheMethods();
new Config(CFG_PATH).then(config => {
this.config = config;
const { sections } = config;
this.db = new Database(sections.database, this);
this.server = new Server(sections.server, this);
this.auth = auth(this);
Expand All @@ -80,8 +82,6 @@ class Application extends EventEmitter {
this.sandbox = this.createSandbox();
this.emit('started');
});
this.cacheDirectory(STATIC_PATH);
this.cacheMethods();
}

async shutdown() {
Expand Down
8 changes: 3 additions & 5 deletions lib/config.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
'use strict';

const EventEmitter = require('events');
const path = require('path');
const fs = require('fs').promises;

class Config extends EventEmitter {
class Config {
constructor(configPath) {
super();
this.sections = {};
this.path = configPath;
this.load();
return this.load();
}

async load() {
const files = await fs.readdir(this.path);
for (const fileName of files) {
this.loadFile(fileName);
}
this.emit('loaded');
return this;
}

loadFile(fileName) {
Expand Down
6 changes: 3 additions & 3 deletions test/unit.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ assert(Config);
const PATH = process.cwd();
const configPath = path.join(PATH, 'config');

const config = new Config(configPath);
config.on('loaded', () => {
(async () => {
const config = await new Config(configPath);
assert(config.sections);
assert(config.sections.database);
assert(config.sections.server);
});
})();