mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-06-13 21:02:08 +08:00
* feat(api): add sentry plugin Apply suggestions from code review Revert "feat(api): add sentry plugin" This reverts commit fcde4ee03e9b83e335a6a2bccd490490e9993597. install sentryNode WIP: create sentry debug WIP: find out why use errorhandler isn't typed correct install sentry add the deleted sentry code create sentry plugin * fix error found through sentry * Polish sentry plugin Co-authored-by: Niraj Nandish <nirajnandish@icloud.com> * duplicate the changes made in the other plugin * add done to seterrorHandler * Fix a typo in sentry option Co-authored-by: Naomi Carrigan <nhcarrigan@gmail.com> * Stop the dns from running if a DSN wasn't provided Co-authored-by: Naomi Carrigan <nhcarrigan@gmail.com> * Polish the function and check the variable value Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * check the dsn dashboard in the env * export dsn value if it isn't sentrydashboard Co-authored-by: Naomi Carrigan <nhcarrigan@gmail.com> * when the value is undefined init errors * revert the if statement * throw an error whenever an environment variable is not right --------- Co-authored-by: Niraj Nandish <nirajnandish@icloud.com> Co-authored-by: Naomi Carrigan <nhcarrigan@gmail.com> Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
71 lines
2.4 KiB
TypeScript
71 lines
2.4 KiB
TypeScript
import assert from 'node:assert';
|
|
import path from 'node:path';
|
|
import { config } from 'dotenv';
|
|
|
|
const envPath = path.resolve(__dirname, '../../../.env');
|
|
const { error } = config({ path: envPath });
|
|
|
|
if (error) {
|
|
console.warn(`
|
|
----------------------------------------------------
|
|
Warning: .env file not found.
|
|
----------------------------------------------------
|
|
Please copy sample.env to .env
|
|
|
|
You can ignore this warning if using a different way
|
|
to setup this environment.
|
|
----------------------------------------------------
|
|
`);
|
|
}
|
|
|
|
function isAllowedEnv(env: string): env is 'development' | 'production' {
|
|
return ['development', 'production'].includes(env);
|
|
}
|
|
|
|
assert.ok(process.env.FREECODECAMP_NODE_ENV);
|
|
assert.ok(isAllowedEnv(process.env.FREECODECAMP_NODE_ENV));
|
|
assert.ok(process.env.AUTH0_DOMAIN);
|
|
assert.ok(process.env.AUTH0_AUDIENCE);
|
|
assert.ok(process.env.API_LOCATION);
|
|
assert.ok(process.env.SESSION_SECRET);
|
|
assert.ok(process.env.FCC_ENABLE_SWAGGER_UI);
|
|
assert.ok(process.env.FCC_ENABLE_DEV_LOGIN_MODE);
|
|
|
|
if (process.env.FREECODECAMP_NODE_ENV !== 'development') {
|
|
assert.ok(process.env.PORT);
|
|
assert.ok(process.env.MONGOHQ_URL);
|
|
assert.ok(process.env.SENTRY_DSN);
|
|
assert.notEqual(
|
|
process.env.SENTRY_DSN,
|
|
'dsn_from_sentry_dashboard',
|
|
`The DSN from Sentry's dashboard should be used.`
|
|
);
|
|
assert.notEqual(
|
|
process.env.SESSION_SECRET,
|
|
'a_thirty_two_plus_character_session_secret',
|
|
'The session secret should be changed from the default value.'
|
|
);
|
|
assert.ok(
|
|
process.env.FCC_ENABLE_DEV_LOGIN_MODE !== 'true',
|
|
'Dev login mode MUST be disabled in production.'
|
|
);
|
|
}
|
|
|
|
export const MONGOHQ_URL =
|
|
process.env.MONGOHQ_URL ??
|
|
'mongodb://localhost:27017/freecodecamp?directConnection=true';
|
|
export const FREECODECAMP_NODE_ENV = process.env.FREECODECAMP_NODE_ENV;
|
|
export const AUTH0_DOMAIN = process.env.AUTH0_DOMAIN;
|
|
export const AUTH0_AUDIENCE = process.env.AUTH0_AUDIENCE;
|
|
export const PORT = process.env.PORT || '3000';
|
|
export const API_LOCATION = process.env.API_LOCATION;
|
|
export const SESSION_SECRET = process.env.SESSION_SECRET;
|
|
export const FCC_ENABLE_SWAGGER_UI =
|
|
process.env.FCC_ENABLE_SWAGGER_UI === 'true';
|
|
export const FCC_ENABLE_DEV_LOGIN_MODE =
|
|
process.env.FCC_ENABLE_DEV_LOGIN_MODE === 'true';
|
|
export const SENTRY_DSN =
|
|
process.env.SENTRY_DSN === 'dsn_from_sentry_dashboard'
|
|
? ''
|
|
: process.env.SENTRY_DSN;
|