1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-07-04 11:36:37 -04:00

consolidate environment variable parsing

This commit is contained in:
2022-09-12 15:42:56 -04:00
parent 0373f806f6
commit c64d6cfb52
7 changed files with 434 additions and 412 deletions

View File

@ -5,3 +5,8 @@ export const NOTES_DIR = "notes";
// normalize the timestamp saved when building/deploying (see next.config.js) and fall back to right now:
export const RELEASE_DATE = new Date(process.env.RELEASE_DATE || Date.now()).toISOString();
// detect if running locally via `next dev` (phase is checked in next.config.js)
export const IS_DEV_SERVER = process.env.IS_DEV_SERVER === "true";
export const BUILD_ENV = process.env.VERCEL_ENV || process.env.NEXT_PUBLIC_VERCEL_ENV || process.env.NODE_ENV;

View File

@ -1,6 +1,7 @@
import { serialize } from "next-mdx-remote/serialize";
import { minify } from "uglify-js";
import { getNoteData } from "./parse-notes";
import { IS_DEV_SERVER } from "../config/constants";
// remark/rehype markdown plugins
import remarkGfm from "remark-gfm";
@ -34,18 +35,17 @@ export const compileNote = async (slug: string): Promise<NoteWithSource> => {
},
});
// HACK: next-mdx-remote v4 doesn't (yet?) minify compiled JSX output, see:
// TODO: next-mdx-remote v4 doesn't (yet?) minify compiled JSX output, see:
// https://github.com/hashicorp/next-mdx-remote/pull/211#issuecomment-1013658514
// ...so for now, let's do it manually (and conservatively) with uglify-js when building for production.
const compiledSource =
process.env.IS_DEV_SERVER !== "true"
? minify(source.compiledSource, {
toplevel: true,
parse: {
bare_returns: true,
},
}).code
: source.compiledSource;
const compiledSource = IS_DEV_SERVER
? source.compiledSource
: minify(source.compiledSource, {
toplevel: true,
parse: {
bare_returns: true,
},
}).code;
return {
frontMatter,

View File

@ -1,4 +1,5 @@
import { PrismaClient } from "@prisma/client";
import { IS_DEV_SERVER } from "../config/constants";
// PrismaClient is attached to the `global` object in development to prevent
// exhausting your database connection limit.
@ -18,4 +19,4 @@ export const prisma =
log: ["query"],
});
if (process.env.IS_DEV_SERVER === "true") global.prisma = prisma;
if (IS_DEV_SERVER) global.prisma = prisma;

View File

@ -1,11 +1,12 @@
import * as Sentry from "@sentry/node";
import "@sentry/tracing";
import { BUILD_ENV } from "../config/constants";
const IsomorphicSentry = () => {
// https://docs.sentry.io/platforms/node/configuration/options/
Sentry.init({
dsn: process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN || "",
environment: process.env.NODE_ENV || process.env.VERCEL_ENV || process.env.NEXT_PUBLIC_VERCEL_ENV || "",
environment: BUILD_ENV,
tracesSampleRate: 1.0,
});