diff --git a/.env-dist b/.env-dist index a25c30720..19ba55801 100755 --- a/.env-dist +++ b/.env-dist @@ -1,5 +1,8 @@ -# dev, heroku, stage, production -NODE_ENV=dev +# https://nextjs.org/docs/messages/non-standard-node-env +# development, production, test +NODE_ENV=development +# local, heroku, stage, production +APP_ENV=local SERVER_URL=http://localhost:6060 PORT=6060 LOGOS_ORIGIN= diff --git a/esbuild.js b/esbuild.js index dff624d2c..5e4e5fad6 100644 --- a/esbuild.js +++ b/esbuild.js @@ -28,8 +28,8 @@ esbuild.build({ external: ['*.webp', '*.svg'], outdir: 'dist', format: 'esm', - minify: AppConstants.NODE_ENV !== 'dev', - sourcemap: AppConstants.NODE_ENV !== 'dev', + minify: AppConstants.NODE_ENV !== 'development', + sourcemap: AppConstants.NODE_ENV !== 'development', splitting: false, // see note below treeShaking: true, platform: 'neutral', diff --git a/sentry.client.config.ts b/sentry.client.config.ts index 787e7a226..ff4478775 100644 --- a/sentry.client.config.ts +++ b/sentry.client.config.ts @@ -9,12 +9,11 @@ import * as Sentry from "@sentry/nextjs"; Sentry.init({ + environment: process.env.NEXT_PUBLIC_APP_ENV, dsn: process.env.NEXT_PUBLIC_SENTRY_DSN, // Adjust this value in production, or use tracesSampler for greater control - tracesSampleRate: ["development", "heroku"].includes(process.env.NODE_ENV) - ? 1.0 - : 0.1, + tracesSampleRate: ["development"].includes(process.env.NODE_ENV) ? 1.0 : 0.1, // Setting this option to true will print useful information to the console while you're setting up Sentry. debug: false, diff --git a/sentry.server.config.ts b/sentry.server.config.ts index 8a7362b5e..a4ffb5474 100644 --- a/sentry.server.config.ts +++ b/sentry.server.config.ts @@ -9,6 +9,7 @@ import * as Sentry from "@sentry/nextjs"; Sentry.init({ + environment: process.env.APP_ENV, dsn: process.env.SENTRY_DSN, // Adjust this value in production, or use tracesSampler for greater control diff --git a/src/app.js b/src/app.js index a5ce92b43..108bf03a5 100644 --- a/src/app.js +++ b/src/app.js @@ -24,12 +24,12 @@ import { noSearchEngineIndex } from './middleware/noSearchEngineIndex.js' import { RateLimitError } from './utils/error.js' const app = express() -const isDev = AppConstants.NODE_ENV === 'dev' +const isDev = AppConstants.NODE_ENV === 'development' // init sentry Sentry.init({ dsn: AppConstants.SENTRY_DSN, - environment: AppConstants.NODE_ENV, + environment: AppConstants.APP_ENV, debug: isDev, beforeSend (event, hint) { if (!hint.originalException.locales || hint.originalException.locales[0] === 'en') return event // return if no localization or localization is in english diff --git a/src/app/api/v1/user/welcome-scan/progress/route.ts b/src/app/api/v1/user/welcome-scan/progress/route.ts index eb76156b1..ee4f9cead 100644 --- a/src/app/api/v1/user/welcome-scan/progress/route.ts +++ b/src/app/api/v1/user/welcome-scan/progress/route.ts @@ -53,7 +53,8 @@ export async function GET( // Store scan results only for development environments. if ( scan.status === "finished" && - process.env.NODE_ENV === "development" + (process.env.NODE_ENV === "development" || + process.env.APP_ENV === "heroku") ) { const allScanResults = await getAllScanResults(profileId); await setOnerepScanResults(profileId, scan.id, { diff --git a/src/appConstants.js b/src/appConstants.js index 132adf634..331f7fc0e 100644 --- a/src/appConstants.js +++ b/src/appConstants.js @@ -8,6 +8,7 @@ dotenv.config() const requiredEnvVars = [ 'ADMINS', + 'APP_ENV', 'COOKIE_SECRET', 'CSRF_SECRET', 'DATABASE_URL', @@ -65,8 +66,7 @@ const optionalEnvVars = [ /** @type {Record} */ const AppConstants = { } -// @ts-ignore TS thinks NODE_ENV can't be "heroku". Shut up TS, you're drunk! -if (!process.env.SERVER_URL && (process.env.NODE_ENV) === 'heroku') { +if (!process.env.SERVER_URL && (process.env.APP_ENV) === 'heroku') { process.env.SERVER_URL = `https://${process.env.HEROKU_APP_NAME}.herokuapp.com` } diff --git a/src/db/knexfile.js b/src/db/knexfile.js index 149622fb5..8f57a96e4 100644 --- a/src/db/knexfile.js +++ b/src/db/knexfile.js @@ -8,9 +8,9 @@ import pgConnectionStr from 'pg-connection-string' import AppConstants from '../appConstants.js' -const { DATABASE_URL, NODE_ENV } = AppConstants +const { DATABASE_URL, APP_ENV, NODE_ENV } = AppConstants const connectionObj = pgConnectionStr.parse(DATABASE_URL) -if (NODE_ENV === 'heroku') { +if (APP_ENV === 'heroku') { // @ts-ignore TODO: Check if this typing error is correct, or if the types are wrong? connectionObj.ssl = { rejectUnauthorized: false } } diff --git a/src/middleware/error.js b/src/middleware/error.js index e956362a6..9e42f3cd4 100644 --- a/src/middleware/error.js +++ b/src/middleware/error.js @@ -41,7 +41,7 @@ function errorHandler (err, req, res, next) { success: false, status: errStatus, message: process.env.NODE_ENV !== 'production' ? errMsg : 'Something went wrong', // hide error message when in production - stack: process.env.NODE_ENV === 'dev' ? err.stack : {} // hide stack when not in dev + stack: process.env.NODE_ENV === 'development' ? err.stack : {} // hide stack when not in dev }) } diff --git a/src/middleware/noSearchEngineIndex.js b/src/middleware/noSearchEngineIndex.js index 733fb33fe..31f01d655 100644 --- a/src/middleware/noSearchEngineIndex.js +++ b/src/middleware/noSearchEngineIndex.js @@ -4,9 +4,9 @@ import AppConstants from '../appConstants.js' -const { NODE_ENV } = AppConstants -const noindexEnvs = ['dev', 'heroku', 'stage'] -const noSearchEngineIndex = !noindexEnvs.includes(NODE_ENV) +const { APP_ENV } = AppConstants +const noindexEnvs = ['local', 'heroku', 'stage'] +const noSearchEngineIndex = !noindexEnvs.includes(APP_ENV) ? (_req, _res, next) => next() : (_req, res, next) => { res.header('X-Robots-Tag', 'noindex') diff --git a/src/utils/dockerflow.js b/src/utils/dockerflow.js index ee3702eaa..530712a83 100644 --- a/src/utils/dockerflow.js +++ b/src/utils/dockerflow.js @@ -29,7 +29,7 @@ if (!fs.existsSync(versionJsonPath)) { } export function vers() { - if (AppConstants.NODE_ENV === "heroku") { + if (AppConstants.APP_ENV === "heroku") { /* eslint-disable no-process-env */ return { commit: process.env.HEROKU_SLUG_COMMIT,