Commit 1db36096 authored by nanahira's avatar nanahira

improve config

parent e74c08a3
......@@ -6,6 +6,21 @@ export interface Config {
port: number;
}
const defaultConfig: Config = {
host: '::',
port: 3000,
};
export async function loadConfig(): Promise<Config> {
return yaml.parse(await fs.promises.readFile('./config.yaml', 'utf-8'));
let readConfig: Partial<Config> = {};
try {
const configText = await fs.promises.readFile('./config.yaml', 'utf-8');
readConfig = yaml.parse(configText);
} catch (e) {
console.error(`Failed to read config: ${e.toString()}`);
}
return {
...defaultConfig,
...readConfig,
};
}
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