OpenAuth_server/src/config.ts

76 lines
1.5 KiB
TypeScript
Raw Normal View History

2019-12-16 13:02:51 +00:00
import { parse } from "@hibas123/config";
import { Logging } from "@hibas123/nodelogging";
import * as dotenv from "dotenv";
import moment = require("moment");
export const refreshTokenValidTime = moment.duration(6, "month");
2019-12-16 13:02:51 +00:00
dotenv.config();
export interface DatabaseConfig {
2020-08-07 14:16:39 +00:00
host: string;
database: string;
2019-12-16 13:02:51 +00:00
}
export interface WebConfig {
2020-08-07 14:16:39 +00:00
port: string;
secure: "true" | "false" | undefined;
2019-12-16 13:02:51 +00:00
}
export interface CoreConfig {
2020-08-07 14:16:39 +00:00
name: string;
url: string;
dev: boolean;
2019-12-16 13:02:51 +00:00
}
export interface Config {
2020-08-07 14:16:39 +00:00
core: CoreConfig;
database: DatabaseConfig;
web: WebConfig;
2019-12-16 13:02:51 +00:00
}
2020-08-07 14:16:39 +00:00
const config = (parse(
{
core: {
dev: {
default: false,
type: Boolean,
},
name: {
type: String,
default: "Open Auth",
},
url: String,
2019-12-16 13:02:51 +00:00
},
database: {
2020-08-07 14:16:39 +00:00
database: {
type: String,
default: "openauth",
},
host: {
type: String,
default: "localhost",
},
2019-12-16 13:02:51 +00:00
},
2020-08-07 14:16:39 +00:00
web: {
port: {
type: Number,
default: 3004,
},
secure: {
type: Boolean,
default: false,
},
2019-12-16 13:02:51 +00:00
},
2020-08-07 14:16:39 +00:00
},
"config.ini"
) as any) as Config;
2019-12-16 13:02:51 +00:00
2020-08-07 14:16:39 +00:00
if (process.env.DEV === "true") config.core.dev = true;
2019-12-16 13:02:51 +00:00
if (config.core.dev)
2020-08-07 14:16:39 +00:00
Logging.warning(
"DEV mode active. This can cause major performance issues, data loss and vulnerabilities! "
);
2019-12-16 13:02:51 +00:00
2020-08-07 14:16:39 +00:00
export default config;