Skip to content
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"dbup": "cd dev/db && docker-compose up -d",
"test": "cross-env MB_ENV_FILE=dev/test.env yarn jest --runInBand --no-cache --forceExit --detectOpenHandles",
"tdd": "cross-env MB_ENV_FILE=dev/test.env yarn jest --runInBand --no-cache --forceExit --detectOpenHandles --watchAll",
"knex": "cross-env MB_ENV_FILE=dev/dev.env knex --knexfile=./dev/db/dev.knexfile.ts",
"knex": "cross-env MB_ENV_FILE=dev/dev.env MB_ENV_FILE_OVR=dev-overrides.env knex --knexfile=./dev/db/dev.knexfile.ts",
"knex:prod": "cross-env MB_ENV_FILE=/etc/mintbean-v4/config/prod.env knex --knexfile /etc/mintbean-v4/config/prod.env",
"knex:test": "cross-env MB_ENV_FILE=dev/test.env knex --knexfile ./dev/test/test.knexfile.ts",
"pristine": "yarn knex migrate:latest && yarn knex seed:run && yarn knex:test migrate:latest && yarn knex:test seed:run",
Expand Down
65 changes: 36 additions & 29 deletions src/configProvider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { config, parse } from "dotenv";
import fs from 'fs';
import fs from "fs";
import path from "path";
import * as yup from 'yup';

type Mapper<T> = (x: string) => T;
const defaultMapper: Mapper<string> = (x) => x;
Expand All @@ -16,49 +17,55 @@ function getConfig(key: string, mapper = defaultMapper): any {
}
}

interface ConfigInstance {
MB_KNEXFILE: string;
MB_SESSION_KEY: string;
MB_ENABLE_GRAPHQL_LOGGER: boolean;
MB_ENABLE_GRAPHIQL: boolean;
MB_FORGOT_PASSWORD_TOKEN_DAYS_TO_LIVE: number;
SENDGRID_KEY: string;
SENDGRID_PRINT_ONLY: boolean;
PORT: string;
}
let instance: ConfigInstance;
const instanceSchema = yup.object().shape({
MB_KNEXFILE: yup.string().required(),
MB_SESSION_KEY: yup.string().required(),
MB_ENABLE_GRAPHQL_LOGGER: yup.bool().required(),
MB_ENABLE_GRAPHIQL: yup.bool().required(),
MB_FORGOT_PASSWORD_TOKEN_DAYS_TO_LIVE: yup.number().required(),
SENDGRID_KEY: yup.string().required(),
SENDGRID_PRINT_ONLY: yup.bool().required(),
PORT: yup.number().required(),
}).required();

let instance : yup.InferType<typeof instanceSchema>;

export default () => {
if (!instance) {
const envFilePath = getConfig(`MB_ENV_FILE`);

const overrideEnvFilePath = getConfig(`MB_ENV_FILE_OVR`);

const envFilePath = getConfig("MB_ENV_FILE");

const overrideEnvFilePath = getConfig("MB_ENV_FILE_OVR");

config({
path: path.join(__dirname, `..`, envFilePath),
});

// checks to see if the dev-overrides.env file is present in root directory
if(fs.existsSync(path.join(__dirname, "..", overrideEnvFilePath))) {
if (fs.existsSync(path.join(__dirname, `..`, overrideEnvFilePath))) {
// override
const envConfig = parse(fs.readFileSync(path.join(__dirname, "..", overrideEnvFilePath)));
const envConfig = parse(fs.readFileSync(path.join(__dirname, `..`, overrideEnvFilePath)));

for(const key in envConfig) {
for (const key in envConfig) {
process.env[key] = envConfig[key];
}
}

instance = {
MB_KNEXFILE: getConfig("MB_KNEXFILE"),
MB_SESSION_KEY: getConfig("MB_SESSION_KEY"),
SENDGRID_KEY: getConfig("SENDGRID_KEY"),
MB_ENABLE_GRAPHQL_LOGGER: getConfig("MB_ENABLE_GRAPHQL_LOGGER", (val) => val === "true"),
MB_ENABLE_GRAPHIQL: getConfig("MB_ENABLE_GRAPHIQL", (val) => val === "true"),
SENDGRID_PRINT_ONLY: getConfig("SENDGRID_PRINT_ONLY", (val) => val === "true"),
MB_FORGOT_PASSWORD_TOKEN_DAYS_TO_LIVE: getConfig("MB_FORGOT_PASSWORD_TOKEN_DAYS_TO_LIVE", (val) => +val),
PORT: getConfig("PORT"),
};
instance = instanceSchema.cast({
MB_KNEXFILE: getConfig(`MB_KNEXFILE`),
MB_SESSION_KEY: getConfig(`MB_SESSION_KEY`),
SENDGRID_KEY: getConfig(`SENDGRID_KEY`),
MB_ENABLE_GRAPHQL_LOGGER: getConfig(`MB_ENABLE_GRAPHQL_LOGGER`),
MB_ENABLE_GRAPHIQL: getConfig(`MB_ENABLE_GRAPHIQL`),
SENDGRID_PRINT_ONLY: getConfig(`SENDGRID_PRINT_ONLY`),
MB_FORGOT_PASSWORD_TOKEN_DAYS_TO_LIVE: getConfig(`MB_FORGOT_PASSWORD_TOKEN_DAYS_TO_LIVE`),
PORT: getConfig(`PORT`),
});

try {
instanceSchema.validate(instance);
} catch (err) {
console.error(err.errors);
}
}

return instance;
Expand Down
2 changes: 0 additions & 2 deletions src/frontend/src/layouts/Toasts.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ const countdownStyle = css`
animation-fill-mode: forwards;
`;

import Card, { CardBody, CardHeader, CardHeaderAction } from "../elements/Card";

const ToastCard = styled(Card)`
height: 6em;
padding-top: 0;
Expand Down
3 changes: 1 addition & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1399,8 +1399,7 @@
dependencies:
regenerator-runtime "^0.13.4"


"@babel/runtime@^7.14.6":
"@babel/runtime@^7.14.6", "@babel/runtime@^7.5.5", "@babel/runtime@^7.8.7":
version "7.14.6"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.14.6.tgz#535203bc0892efc7dec60bdc27b2ecf6e409062d"
integrity sha512-/PCB2uJ7oM44tz8YhC4Z/6PeOKXp4K588f+5M3clr1M4zbqztlo0XEfJ2LEzj/FgwfgGcIdl8n7YYjTCI0BYwg==
Expand Down